@Getter @Setter 注解无法解析为类型 [英] @Getter @Setter annotation cannot be resolved to a type

查看:70
本文介绍了@Getter @Setter 注解无法解析为类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动化 JavaBean 中的 getter 和 setter 方法.

因为,方法和字段命名约定是为 Beans 描述的@命名约定,必须有一种方法来使用这种约定,以避免样板代码,例如为每个 bean 编写 getter 和 setter 方法.我在这里找到了一种这样的方法.

我在我的 Windows 机器上使用带有 Java SE 6 的 Eclipse Helios IDE.尽管 Eclipse 确实提供了一种无需显式编写即可生成 getter 和 setter 方法的方法,但使用注释会使代码更加清晰和可读.

但是,当我在 Eclipse 中编写以下代码时,我收到以下错误@编译时:

 private @Getter @Setter int price;

错误:

Getter 无法解析为类型.
Setter 无法解析为类型.

我该如何解决??

解决方案

@Getter@Setter 不是 Java 的一部分.Project Lombok 有这些名称的注释,因此您应该研究如何设置它.>

I am trying to automatize the getter and setter methods in my JavaBean.

Since, method and field naming conventions are described for Beans @ Naming Convention, there has to be a way to use this conventions in-order to avoid the boiler plate code such as writing getter and setter methods for every bean. I found one such way here.

I am using Eclipse Helios IDE with Java SE 6 in my Windows machine. Though Eclipse do provides a way to generate getter and setter methods without explicitly writing them, using annotations would make the code much more cleaner and readable.

However, when I write the following code in my Eclipse I get the following error @ Compile-time:

    private @Getter @Setter int price;

Error :

Getter cannot be resolved to a type.
Setter cannot be resolved to a type.

How do I resolve it??

解决方案

@Getter and @Setter are not part of Java. Project Lombok has annotations with these names, so you should look into how to set it up.

这篇关于@Getter @Setter 注解无法解析为类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆