I’ve a question which is very confusing to me. First i will tell what i know about instantiating an object from a specific class..
-
We create an instance ( or object ) of a class, by declaring a type ( may also be an Interface type ), a reference name ( variable ) and on the other side of equal operator we use keyword new to reserve memory for a specific type of object. We finish a statement with, a constructor call ( cant be interface, since interface cannot be instantiated )
-
Some classes have constructor, declared as private. That means we can’t use constructor call to create a new object.
-
As alternative some classes “allow” instantiating an object via public or static methods, for example Calendar class. We get an instance of this class like this:
Calendar variableRepresentingAnInstanceOrObject = Calendar.getInstance();
(if something is wrong above, you can correct me )
Ok now i have a question, since i’m java begginer i’m a little confused with some classes in JodaTime libary.
There are some classes called Minutes or Hours etc. I already read documentation for those classes but i can’t understand how to insantiate them. I’cant use keyword new since constructor is private ( eclipse is telling me that constructor is not visible). In declaration for minutes ( but not for hours ), says: The number of minutes is set in the constructor, and may be queried using getMinutes(). They neither have public or static methods to use ( like calendar class ), as far as i know.
Which constructor? How to even call it?
Did i missed something in documentation, or did i missed something when i was learning java? Can someone please explain this to me. I will really appriciate. Thanks in advance =)
The class provides a few factory methods, such as:
Check the
staticmethods in the javadoc that return aMinutesobject, most of them are factory methods.