0

I was reading about Java beans, and all the examples I came across use standard Java types (String, int, etc) for class variables. Can I use variables of my own class type in a bean?

Eg.

class MyBean implements java.io.Serializable{
    MyObj mo;
    public MyBean(){}
    //Getter and setter for mo
}

(Writing this from a phone, so apologize for no formatting)

2
  • 2
    Yes you can. When reaching your PC, try it. Commented Jul 25, 2013 at 21:38
  • Thanks for clearing the confusion! Commented Jul 27, 2013 at 5:08

1 Answer 1

1

Yes, you can.

You can implement your own business logic using POJO defined by yourself plugging reusable components as well.

If you use JSF remember to create setter and getter for your variables if you want to access them from your JSP/Facelets pages. The naming convention is pretty standard, if you have a String named 'foo' the framework will call the

public String getFoo() 
{ 
  return foo;
}  

method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.