forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
30 lines (20 loc) · 684 Bytes
/
Main.java
File metadata and controls
30 lines (20 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package modern.challenge;
import java.lang.reflect.Field;
public class Main {
// Run this code in JDK 8
public static void main(String[] args)
throws NoSuchFieldException, IllegalAccessException {
String user = "guest";
System.out.println("User is of type: " + user);
Class<String> type = String.class;
Field field = type.getDeclaredField("value");
field.setAccessible(true);
char[] chars = (char[]) field.get(user);
chars[0] = 'a';
chars[1] = 'd';
chars[2] = 'm';
chars[3] = 'i';
chars[4] = 'n';
System.out.println("User is of type: " + user);
}
}