BAEL-4399: Added changes as per review comment
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.exceptions.nosuchfielderror;
|
||||
|
||||
public class Dependent {
|
||||
// This needed to be commented post compilation of NoSuchFielDError and Compile
|
||||
public static String message = "Hello Baeldung!!";
|
||||
// This needed to be commented post compilation of NoSuchFielDError and Compile
|
||||
public static String message = "Hello Baeldung!!";
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.baeldung.exceptions.nosuchfielderror;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NoSuchFieldError {
|
||||
// String message = "Hello Baeldung!!!";
|
||||
|
||||
public static String getMessage() throws ClassNotFoundException, NoSuchFieldException, SecurityException,
|
||||
IllegalArgumentException, IllegalAccessException {
|
||||
NoSuchFieldError clss = new NoSuchFieldError();
|
||||
Class<?> aClass = Class.forName(clss.getClass().getName());
|
||||
Field field = aClass.getDeclaredField("message");
|
||||
field.setAccessible(true);
|
||||
String msgStr = (String) field.get(clss);
|
||||
return msgStr;
|
||||
}
|
||||
|
||||
public static String getDependentMessage() {
|
||||
return Dependent.message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.exceptions.nosuchfielderror;
|
||||
|
||||
public class NoSuchFieldErrorExample {
|
||||
|
||||
public static String getDependentMessage() {
|
||||
return Dependent.message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user