Java的getter和setter [英] Java Getters and Setters

查看:158
本文介绍了Java的getter和setter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有用Java创建getter和setter一个更好的标准方式?

Is there a better standard way to create getters and setters in Java?

这是很冗长有明确定义的getter和setter每个变量。有没有更好的标准的标注方法?

It is quite verbose to have to explicitly define getters and setters for each variable. Is there a better standard annotations approach?

春节是否有这样的事?

即使C#有自己的属性。

Even C# has properties.

推荐答案

我不知道,如果你认为这是标准,但的项目龙目岛解决了这个问题。他们使用注解来代替多的Java的冗长的。

I'm not sure if you'd consider it 'standard', but Project Lombok addresses this problem. They use annotations to replace much of the verbosity of Java.

有些人正在寻找替代Java的兄弟姐妹语言,比如Groovy或斯卡拉。恐怕还需要一段岁月 - 如果在清一色的JSR计算出一个标准化的方式来修复此在Java中之前适当。

Some people are looking at alternative Java sibling languages, such as Groovy or Scala. I'm afraid it will take some years -if at all- before the JSR figures out a "standardized" way to "fix" this in Java proper.

这篇关于Java的getter和setter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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