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

Creating Own Object in Method

 
Debojit Sinha
Ranch Hand
Posts: 66
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, people,
Why is it legal to create object of own class from a method?
Thank You.
 
Yogesh Gnanapraksam
Ranch Hand
Posts: 133
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand your question.
Do you mean to say that it should not be allowed ?
 
pankaj vijay
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give me a reason why should be it illegal ???
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean something like this:

There's nothing wrong with creating any kind of object in a method, including an object of the class that the method is in. Why do you think it's strange that this is legal?
 
Debojit Sinha
Ranch Hand
Posts: 66
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Er, I think I phrased the question incorrectly, sorry.
My point was that since classes are created at compnile time, and, if a constructor to itself is called within it, should not here be an error? Since, after all, the class to be constructed is not in existence yet. In all probability I am wrong, and look forward to your clarification. Thank You.
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean something like this:
That will cause a StackOverflowError yes.
 
Debojit Sinha
Ranch Hand
Posts: 66
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I took so long to answer, project lead was being a nazi, but thanks for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic