• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class.... verifyError.

 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a static inner class if we try to initiate like this
new outer().new inner();
there's a java.lang.verifyError.
Could anyone tell me the proper reason ?
 
Rajiv Ranjan
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nasir:
Ramember the name "Static" , hence try this out
new outer().inner();
Thanks
 
Brian, Cavanagh
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nasir,
You can declare an instance of a static inner class without an instance of the enclosing class.
Therefore, you could drop the OuterOne in
OuterOne.InnerOne in = new OuterOne().new InnerOne();
making it simply
InnerOne in = new InnerOne();
Hope this helps
Brian
 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
But I need some explaination about verifyError .I mean what kind of verification does the compiler do.
In the case of static method you can use "new classname().staticmethod();"
but why can't with static inner class?
 
saran_dd
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//Please try this. It will solve your problem. There is no verify error.
class Inner1
{
void print()
{
System.out.println("Outer method");
}
static class a
{
int b=10;
void change()
{
System.out.println(b+"Hello World!");
//print();
}
}
public static void main(String[] args)
{
a a1 = new Inner1().new a();
a a2 = new Inner1.a();
a2.change();
a1.change();
}
}

------------------
D.Saravanan,
Software Engineer,
Birla Consultancy & Software Services,
Mumbai.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic