无效重复类定义错误:Invalid duplicate class definition of class xxxx

发布时间 2023-07-18 17:24:13作者: colfish

Description

startup failed:
/xxxx/OrderFixFile.groovy: 5: Invalid duplicate class definition of class OrderFixFile : The source /xxxx/OrderFixFile.groovy contains at least two definitions of the class OrderFixFile.
One of the classes is an explicit generated class using the class statement, the other is a class generated from the script body based on the file name. Solutions are to change the file name or to change the class name.

Reason

由于该类的文件编码为UTF-8 with BOM,需要将文件编码改为UTF-8。选中编码错误的文件->File->File Properties->Remove BOM即可

image

BOM解释

BOM(byte order mark)是为 UTF-16 和 UTF-32 准备的,用于标记字节序(byte order)。
「UTF-8」和「带 BOM 的 UTF-8」的区别就是有没有 BOM。即文件开头有没有 U+FEFF。
通常BOM是用来标示Unicode纯文本字节流的,用来提供一种方便的方法让文本处理程序识别读入的.txt文件是哪个Unicode编码(UTF-8,UTF-16BE,UTF-16LE)。微软在 UTF-8 中使用 BOM 是因为这样可以把 UTF-8 和 ASCII 等编码明确区分开,但这样的文件在 Windows 之外的操作系统里会带来问题。

防止再次出现,可以在全局设置文件默认编码为UTF-8

image