Enabling assertions and also demonstrating that fields can be moved up to one level in the class hierarchy
5 import api.HelloFieldClass;
6 import api.HelloInterface;
10 * @author Jaroslav Tulach <jtulach@netbeans.org>
13 public static void main(String[] args) throws Exception {
14 boolean assertionsOn = false;
15 assert assertionsOn = true;
17 throw new IllegalStateException("Enable assertions!");
20 HelloClass clazz = new ImplClass();
21 assert "Hello Unknown!".equals(clazz.sayHello());
22 assert "Hello Jaroslav!".equals(clazz.sayHelloTo("Jaroslav"));
23 System.err.println("Who defines sayHello(): " + clazz.getClass().getSuperclass().getMethod("sayHello"));
25 HelloInterface iface = new ImplInterface();
26 assert "Hello Unknown!".equals(iface.sayHello());
27 assert "Hello Jaroslav!".equals(iface.sayHelloTo("Jaroslav"));
28 System.err.println("Who defines sayHello(): " + iface.getClass().getInterfaces()[0].getMethod("sayHello"));
30 HelloFieldClass fieldClass = new HelloFieldClass();
31 assert "Hello".equals(fieldClass.field);
32 System.err.println("Who defines field: " + fieldClass.getClass().getField("field"));