Created
September 26, 2017 05:49
-
-
Save hishidama/17b7d6673a7f07ffa3771ba75f937c2f to your computer and use it in GitHub Desktop.
getなのに、なぜエラーメッセージが「set」なのか?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example; | |
import java.lang.reflect.Field; | |
public class FieldExample { | |
public static void main(String[] args) throws Exception { | |
Field field = Integer.class.getDeclaredField("value"); | |
field.setAccessible(true); | |
field.getInt(""); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exception in thread "main" java.lang.IllegalArgumentException: Can not set final int field java.lang.Integer.value to java.lang.String | |
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) | |
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) | |
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58) | |
at sun.reflect.UnsafeQualifiedIntegerFieldAccessorImpl.getInt(UnsafeQualifiedIntegerFieldAccessorImpl.java:58) | |
at java.lang.reflect.Field.getInt(Field.java:574) | |
at example.FieldExample.main(FieldExample.java:10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment