Java value object

I'm new to Java and I need to create a value object (maybe it's called a 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 as follows:

public boolean some_function() 
{               
    User u = new User();

    return true; // got a breakpoint here
}

So, if I comment on "User u = new User ();" I will go to the breakpoint, but if I save it as above, it just stops working.

On the other hand, I save both files in the same folder, so eclipse does not import the file, is this correct or should I import it?

EDIT:

After a while I found out that I had to import the file manually, I thought I tried it, but apparently did not.

0
source share
4 answers

, , , , , - " u = ();" User - , .

, :

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

some_function(). , .

, , , , , , some_function(), "" - - , . - User , some_function() - ? , import some_function() User?

+1

User()?

0

,

id = 99;

.

I don’t understand what you mean when importing into Eclipse - I have all my code in Eclipse, however I suspect that your application does not see the User class correctly. You might even get a compilation error. Create your packages and classes in Eclipse, let it sort the directories for you.

Show us the entire application class, including user import.

0
source

Place a breakpoint on User u = new User();and go to the constructor to see what it does.

0
source

Source: https://habr.com/ru/post/1769284/


All Articles