java对象没塞值,java值对象

I'm new to Java and I have to create a value object, (maybe it's called mapped object in Java) but my code doesn't seem to work, here is the value object:

package ....;

public class User {

private int id;

private int uid;

private String name;

public User()

{

// do something here

}

}

and I assign a new value object like this:

public boolean some_function()

{

User u = new User();

return true; // got a breakpoint here

}

So if I comment out "User u = new User();" I will go to the breakpoint but if I keep it like above it will just stop running.

On a side note, I keep both the files in the same folder so eclipse doesn't import the file, is this correct or should I import it?

EDIT:

After some time I found out that I had to import the file manually, I thought I tried that but apparently I didn't.

解决方案

Dennis, if the code as you posted it is the exact code you're running, then this makes no sense -- the "User u = new User();" call would return you a new User object without any issues, since your constructor is empty.

To demonstrate that to yourself, change your constructor to:

public User() {

System.out.println("I'm inside the User constructor!");

}

and call your some_function() function again. You should see that line printed out to your console.

Given what you're reporting and the code you're showing, I suspect that the class that contains some_function() isn't "seeing" the User class -- you're importing some other User class rather than the one you created. Are the two classes -- the User class and the class which contains some_function() -- in the same package? If not, what import statement at the top of the some_function()-containing class is handling the import of your User class?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值