在java中制作一个用于对多个值进行分组的模型
这当然是显而易见的,但我坚持不懈。
我想要这样的东西,
group1 {
name="boo";
gender="male";
}
...
groupN {
name="baa";
gender="female";
}
所有的小组都有相同的成员。 当我制作函数时,
function(Group group) {
blabla = group.name;
bloblo = group.gender;
}
我知道该怎么做,但它一点也不漂亮,而且我确信有一种方法可以干净地完成它
This is surely obvious but I'm stuck on it.
I want to have something like that
group1 {
name="boo";
gender="male";
}
...
groupN {
name="baa";
gender="female";
}
all the group have the same member.
and when i make function
function(Group group) {
blabla = group.name;
bloblo = group.gender;
}
I know how to do it but it's not pretty at all , and I'm sure there is a way to do it cleanly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 的设计初衷并不是为了美观,也不是一种函数式语言。很可能,最简单的方法/最自然的方法就是使用没有“函数”的普通循环,
也许如果您可以更具体,我们可以更具体地帮助您。
Java is not designed to be pretty or a functional language. It is fairly likely that the simplest way/most natural way to do what you want is to use a plain loop without a "function"
Perhaps if you can be more specific we can help you more specifically.
您正在描述类。这正是您的代码的 Java 等价物:
我建议您阅读一本介绍性 Java 书籍并阅读有关 OOP 的章节。 关于 OOP 的 Java 教程章节也适用。
You're describing classes. This is the exact Java equivalend of your code:
I suggest getting an introductory Java book and reading the chapters on OOP. The Java tutorial chapter on OOP works as well.