문제

I have a doubt regarding POJO.

Take below example

public class User
{
     String user="";
     String password="";
     String firstName="";
     String lastName="";
     ChallengeQuestions challengeQuestions;

     //getter and setters for these prooperties
}

public class ChallengeQuestions
{
    String question="";
    String answer="";

    //getter and setters for these properties
}

Here is my question, whether User class is a POJO or not.

Thanks,
Narendra

도움이 되었습니까?

해결책

POJO i.e. Plain Old Java Object refers to all user defined types that do not have to extend a specific/special prespecified class or specialized prespecified interface.
Your class fits in this category so it is a POJO.

다른 팁

Yes, it is. See 'Plain Old Java Object' (Wikipedia).

The term "POJO" is mainly used to denote a Java object which does not follow any of the major Java object models, conventions, or frameworks.

I would have said that a POJO is distinct from a JavaBean. A POJO does not need to have setters or getters and it would more clearly be a POJO without them.

Your comments suggests you intended to add getters and setters to follow the JavaBean standard and as such this is not a POJO as it is intended to comply with the JavaBean convention.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top