@Test public void testFields() throws Exception { JiteClass jiteClass = new JiteClass("testFields", p(Object.class), new String[0]) {{ defineField("foo", ACC_PUBLIC | ACC_STATIC, ci(String.class), "bar"); }}; Class<?> clazz = new DynamicClassLoader().define(jiteClass); Field foo = clazz.getDeclaredField("foo"); assertEquals("foo field was not a string", String.class, foo.getType()); assertEquals("foo field was not set to 'bar'", "bar", foo.get(null)); }
public FieldDefinition defineField(String fieldName, int modifiers, String signature, Object value) { FieldDefinition field = new FieldDefinition(fieldName, modifiers, signature, value); this.fields.add(field); return field; }
JiteClass implements Opcodes { public FieldDefinition defineField(String fieldName, int modifiers, String signature, Object value) { FieldDefinition field = new FieldDefinition(fieldName, modifiers, signature, value); this.fields.add(field); return field; } }
JiteClass implements Opcodes { public FieldDefinition defineField(String fieldName, int modifiers, String signature, Object value) { FieldDefinition field = new FieldDefinition(fieldName, modifiers, signature, value); this.fields.add(field); return field; } JiteClass(String className);  JiteClass(String className, String[] interfaces);  JiteClass(String className, String superClassName, String[] interfaces); }
JiteClass implements Opcodes { public FieldDefinition defineField(String fieldName, int modifiers, String signature, Object value) { FieldDefinition field = new FieldDefinition(fieldName, modifiers, signature, value); this.fields.add(field); return field; } JiteClass(String className);  JiteClass(String className, String[] interfaces);  JiteClass(String className, String superClassName, String[] interfaces); AnnotationData annotate(Class<?> annotationType); int getAccess(); String getClassName(); String getParentClassName(); String reserveLambda(); void setAccess(int access); void setParentClassName(String parentClassName); void setSourceFile(String sourceFile); void setSourceDebug(String sourceDebug); void addChildClass(JiteClass child); void addChildClass(String innerName, JiteClass child); List<JiteClass> getChildClasses(); void defineMethod(String methodName, int modifiers, String signature, CodeBlock methodBody); FieldDefinition defineField(String fieldName, int modifiers, String signature, Object value); void defineDefaultConstructor(); void defineDefaultConstructor(int access); byte[] toBytes(); void addAnnotation(AnnotationData annotation); byte[] toBytes(JDKVersion version); }
JiteClass implements Opcodes { public FieldDefinition defineField(String fieldName, int modifiers, String signature, Object value) { FieldDefinition field = new FieldDefinition(fieldName, modifiers, signature, value); this.fields.add(field); return field; } JiteClass(String className);  JiteClass(String className, String[] interfaces);  JiteClass(String className, String superClassName, String[] interfaces); AnnotationData annotate(Class<?> annotationType); int getAccess(); String getClassName(); String getParentClassName(); String reserveLambda(); void setAccess(int access); void setParentClassName(String parentClassName); void setSourceFile(String sourceFile); void setSourceDebug(String sourceDebug); void addChildClass(JiteClass child); void addChildClass(String innerName, JiteClass child); List<JiteClass> getChildClasses(); void defineMethod(String methodName, int modifiers, String signature, CodeBlock methodBody); FieldDefinition defineField(String fieldName, int modifiers, String signature, Object value); void defineDefaultConstructor(); void defineDefaultConstructor(int access); byte[] toBytes(); void addAnnotation(AnnotationData annotation); byte[] toBytes(JDKVersion version); static final String[] INTERFACES; }