void method2() { ClassA a = new ClassA(); // :: error: (contracts.precondition.not.satisfied) a.getValue(); // :: error: (contracts.precondition.not.satisfied) method(); }
void method3() { ensuresNonNull(); method(); ClassA a = new ClassA(); a.ensuresNonNull(); a.getValue(); }
@Test(groups = {"fast-unit"}) public void pathWhereAClassesFilesAreStored_should_differForDifferentClasses() { ClassA classA = new ClassA(); ClassB classB = new ClassB(); boolean isDifferentClassses = !classA.getClass().getName().equals(classB.getClass().getName()); assertTrue(isDifferentClassses); Path classAStoragePath = classA.getPathWhereFilesAreStored(); Path classBStoragePath = classB.getPathWhereFilesAreStored(); assertTrue(!classAStoragePath.equals(classBStoragePath)); }
public static void main(String[] args) { ClassA ca = new ClassA(); System.out.println("a : " + ca.a); System.out.println("b : " + ca.getB()); System.out.println("c : " + ca.getC()); System.out.println( "d : " + ca .getD()); // The field ClassA.d is not visible. Since the variable d is private, // other classes are not able to access it. }
@Test public void testParseSingle() throws Exception { final AhcPropertyAccessor accessor = new AhcMapperExpressionParser(AhcMapperLogger.DEBUG_STDOUT) .parse(ClassA.class, "firstName", String.class, null, true); assertEquals(MethodBasedPropertyAccessor.class, accessor.getClass()); assertEquals(true, accessor.isPrimary()); assertEquals(true, accessor.isReadable()); assertEquals(true, accessor.isWritable()); assertEquals("firstName", accessor.getName()); final ClassA a = new ClassA(); accessor.setValue(a, "first"); assertEquals("first", a.getFirstName()); assertEquals("first", accessor.getValue(a)); }
static void main() { ClassA instanceA = new ClassA(); instanceA.method1(); instanceA.method2(); System.out.println("-------------------"); ClassB instanceB = new ClassB(); instanceB.method1(); instanceB.method2(); System.out.println("-------------------"); ClassC instanceC = new ClassC(); instanceC.method1(); instanceC.method2(); }
@Test public void testParseOgnl() throws Exception { final AhcPropertyAccessor accessor = new AhcMapperExpressionParser(AhcMapperLogger.DEBUG_STDOUT) .parse(ClassA.class, "phone[0].phone", String.class, null, true); assertEquals(OgnlPropertyAccessor.class, accessor.getClass()); assertEquals(true, accessor.isPrimary()); assertEquals(true, accessor.isReadable()); assertEquals(true, accessor.isWritable()); assertEquals("phone[0].phone", accessor.getName()); final ClassA a = new ClassA(); a.getPhone().add(new InnerClassA()); accessor.setValue(a, "xyz"); assertEquals("xyz", a.getPhone().get(0).getPhone()); assertEquals("xyz", accessor.getValue(a)); }
public static void main(String[] args) { // TODO Auto-generated method stub ClassA a = new ClassB(); a.func1(); // /* * class A , class B 如果 func1() 是static的 , 则 a.func1() 调用的是 classA 中的 func1() 。 反之,则调用 classB中的func1() */ // ClassB b = new ClassA(); // failed. HashMap<Integer> hashmap = new Map<Integer>() 是不对的 // b.func1(); // // HashMap<Integer> hashmap = new Map<Integer>(); /* * Exception in thread "main" java.lang.Error: Unresolved compilation problems: Incorrect number of arguments for type HashMap<K,V>; it cannot be parameterized with arguments <Integer> Incorrect number of arguments for type Map<K,V>; it cannot be parameterized with arguments <Integer> Syntax error on token "Invalid Character", ; expected */ }
@EnsuresNonNull("field.value") void ensuresNonNull() { field.ensuresNonNull(); }