BCEL 6을 권장합니다. ASM을 사용할 수도 있지만 BCEL은 사용하기가 더 쉽다고 들었습니다. 다음은 최종 필드를 만들기위한 간단한 테스트 방법입니다 : 물론
public static void main(String[] args) throws Exception {
System.out.println(F.class.getField("a").getModifiers());
JavaClass aClass = Repository.lookupClass(F.class);
ClassGen aGen = new ClassGen(aClass);
for (Field field : aGen.getFields()) {
if (field.getName().equals("a")) {
int mods = field.getModifiers();
field.setModifiers(mods | Modifier.FINAL);
}
}
final byte[] classBytes = aGen.getJavaClass().getBytes();
ClassLoader cl = new ClassLoader(null) {
@Override
protected synchronized Class<?> findClass(String name) throws ClassNotFoundException {
return defineClass("F", classBytes, 0, classBytes.length);
}
};
Class<?> fWithoutDeprecated = cl.loadClass("F");
System.out.println(fWithoutDeprecated.getField("a").getModifiers());
}
, 당신은 실제로 파일로 디스크에 당신의 클래스를 작성하고 그들을 항아리 것이라고는하지만이 일을 시도하기위한 쉽습니다. 나는 BCEL 6 편리하지 않아도, 그래서 주석을 제거하기 위해이 예제를 수정할 수 없습니다,하지만 난 코드가 뭔가 같은 것 상상 : 코드를 난독에
public static void main(String[] args) throws Exception {
...
ClassGen aGen = new ClassGen(aClass);
aGen.setAttributes(cleanupAttributes(aGen.getAttributes()));
aGen.getFields();
for (Field field : aGen.getFields()) {
field.setAttributes(cleanupAttributes(field.getAttributes()));
}
for (Method method : aGen.getMethods()) {
method.setAttributes(cleanupAttributes(method.getAttributes()));
}
...
}
private Attribute[] cleanupAttributes(Attribute[] attributes) {
for (Attribute attribute : attributes) {
if (attribute instanceof Annotations) {
Annotations annotations = (Annotations) attribute;
if (annotations.isRuntimeVisible()) {
AnnotationEntry[] entries = annotations.getAnnotationEntries();
List<AnnotationEntry> newEntries = new ArrayList<AnnotationEntry>();
for (AnnotationEntry entry : entries) {
if (!entry.getAnnotationType().startsWith("javax")) {
newEntries.add(entry);
}
}
annotations.setAnnotationTable(newEntries);
}
}
}
return attributes;
}
다른 클래스는 어떤 클래스를 참조합니까? 왜 당신은 당신의 안드로이드 애플 리케이션에 포함 된 클래스가 있습니까? –
불행히도 주석을 참조하는 클래스를 제어 할 권한이 없습니다. 다른 라이브러리에서 참조됩니다. –
아직도 궁금한 점이 있습니까?이 수업을 참조하는 도서관은 무엇입니까? –