Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instantiating an anonymous class in multiple places in a program

 
Maciek Makowski
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quote from JLS:


A given anonymous class is only instantiated at a single point in a program.


This does not seem to be true, since we can instantiate a class using reflection:



Am I missing something, or is JLS wrong? The problem is that the argument of "single-point instancing" was used as a rationale for a design decision (namely, that anonymous classes' instance initializers are allowed to throw any exception).
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it's not totally true. But give the author a break--going into a tangent on reflection (an advanced topic) wouldn't do much good for a newbie that doesn't even understand what an anonymous class is.
 
Maciek Makowski
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the thing is this is a quote from the Java Language Specification, so I presume the author wasn't a Java newbie...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic