Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to use the final class that has no constructor?  RSS feed

 
Tanakorn Numrubporn
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I using Ibis (Grid computing API on java base) and I find one final class that I think I have to use it. It has no constructor, so I can't instantiate it. Api doc tells me that this class is class container, which comprises multiple field that I want to use it but I can't.

Please help me

Thank you
Tanakorn
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every class has a constructor.
 
Pavel Kubal
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you look for some factory methods?

Every class has a constructor, but not every constructor is visible.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another possibility: if a class has no declared constructor, then a default constructor will be automatically created, with no arguments. So just calling "new SomeClassName()" should work.

Now if the class has a constructor, but it's private - that's when you may have to look for another way to create it, such as a factory method. Or, some classes are not intended to be instantiated. (See java.lang.Math for example.) You may have to study the API more to understand how the class is to be used. Or if you can give a link to the API of this class, maybe we can help...
 
Tanakorn Numrubporn
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.cs.vu.nl/ibis/api/index.html

Thank you for every reply.
This is the link for that API.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tanakorn Numrubpor:
http://www.cs.vu.nl/ibis/api/index.html

Thank you for every reply.
This is the link for that API.


What's the name of the class you were trying to use?
 
Tanakorn Numrubporn
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oop! sorry the class is GruopMessage
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, have you tried simply calling "new GroupMessage()" like I suggested?
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since i dont see any non-default constructors mentioned in that Javadoc, the default constructor should work:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!