• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reflection: To check whether static block is there or not!  RSS feed

 
Abhishek Chaudhari
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
**Hello.java
public class Hello
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}

static
{
System.out.println("Static Block of Hello");
}
}
///////////////////////////
**Hello2.java
public class Hello2
{
public static void main(String[] args)
{
Class klass = Hello.class;
.......
}
}
///////////////////

Can I somehow know - using reflection - in class Hello2 through 'klass' whether there is a static block in class Hello?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um ... I don't think so. Just curious though, but what possible reason would you have for wanting to know if there is a static initialization block in a class?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!