0

I have field in my class

public int author;

this field contains uniq id of and user stored in my database. for some reasons I can't set here an object of user just the value of his id and also the field needs to be public. Now I would like to creat auto getter for this field that is return and object. So when I do object.author I'll receive object of User not integer. I think that is not possible but I want to check :)

4

1 回答 1

1

在某种程度上,您想要一个自定义自动装箱功能,其中作者更改用户对象。

 User u = object.author;

Java 不提供自定义自动装箱。所以你问的是不可能的。

另一种说法是您想重载=运算符,但 java 不提供该选项。所以再次不可能,这就是原因:http: //www.cafeaulait.org/javafaq.html#xtocid1902938

于 2013-10-09T15:51:34.077 回答