Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

constructor problem

 
ssasi kumar
Greenhorn
Posts: 26
Chrome Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

how to call constuctor from same class method. i am using "this" its generates error then which via constructor call from method in same class...



thanks for all,
sasikumar
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Constructors are not methods and are only invoked during the construction of an object. Why do you want to call one ?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ssasi kumar wrote:
then which via constructor call from method in same class...


the only way to call the constructor from method is by using *new* key word.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:the only way to call the constructor from method is by using *new* key word.

Actually there are other ways, like via Reflection (Class.newInstance())
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:Actually there are other ways, like via Reflection (Class.newInstance())

Yes . thanks
 
ssasi kumar
Greenhorn
Posts: 26
Chrome Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
here i attach my snippet code. there is one error occur, that method called fallen in infinite loop. how to avoid infinite loop..





please reply me.....



 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, does this have something to do with your first post or is this a completely different question? If it is a completely new question, then next time please just post it in a new topic instead of appending it to an existing topic as a reply.

Please UseCodeTags when you post source code - I've added them for you in your post above.

The code you posted does not seem to have an infinite loop. You could get an infinite recursive loop if you'd have one method that calls another, that again calls the one, that again calls the other, ... but I don't see that in the two methods you posted.

Also, the code you posted doesn't even compile. Lines 4 and 5 both contain a return statement. The compiler will complain about unreachable code in line 5 when you try to compile this. Please PostRealCode so that we can really see what's happening and what the problem might be.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic