0

I mean, imports generally don't effect code unless you use something that is unknown in the current file without giving the full qualified identifier, but this one seems weird to me. It's in a few files and is generally unused.

Can "import org.parceler.Generated" be removed savely? Is there any reason to keep it?

The part that stumps me is the word "Generated" here. It seems like this has to be or atleast should be kept, but I don't know why.

I suppose it's autoincluded when using some autogeneration tool, potentially even build into android-studio. But why is the "import org.parceler.Generated" line generated if the import is unused ?

4

1 回答 1

1

如果您使用的是 Parceler,那么它应该生成如下所示的类:

@Generated(value = "org.parceler.ParcelAnnotationProcessor", date = "2016-09-03T09:53-0600")
@SuppressWarnings({
    "unchecked",
    "deprecation"
})
public class ParcelerTestModel$$Parcelable
    implements Parcelable, ParcelWrapper<org.parceler.test.ParcelerTestModel>
{
...

注意@Generated注释。org.parceler如果生成的类在包之外,这需要您提到的导入。

注释在@Generated这里没有多大作用。此注释背后的目的是按照JSR269 标准将生成的代码与用户编写的代码区分开来。

如果您将生成的代码排除在注释处理器的范围之外并自己管理它,那么您可以自由地删除此注释。但是,我不会推荐这种方法,因为它只是管理更多样板文件,这违背了使用 Parceler 等减少样板文件的解决方案的目的。

于 2016-12-25T01:45:05.927 回答