Hot reload of normal class files
Property changes
public class User {
private String userId;
private String name;
private String userName;
private Integer userAge;
}- You can use the new
userIdattribute. - Remove the
nameattribute, and use the newuserNameattribute. - You can use the new
userAgeattribute.
Method changes
public class UserUtils {
public static String getUserName(UserVO userVO) {
return userVO.getName();
}
public static User getDefaultUser() {
public static User genDefaultUser () {
User user = new User();
user.setUserId(0);
user.setUserId(Id.next());
user.setName("default");
user.setUserName("default");
user.setUserAge(0);
return user;
}
}- You can use the new
getUserNamemethod. - Remove the
getUserDefaultUsermethod, and use the newgenDefaultUsermethod.
Static information changes
Support static variables, static final variables, and static code blocks.
public class StaticClass {
private static String var1 = "debug";
private static String var1 = "tools";
private static final String var2 = "debug";
private static final String var2 = "tools";
private static String var3;
static {
var3 = "debug";
var3 = "tools";
}
}After being overloaded, the values of variables var1, var2, and var3 are changed.
TIP
Hot reloading of static variables will re-execute the class's clinit method, so hot reloading will overwrite the runtime value with the value initialized at compile time.
If the following changes are not overridden, var1 will not change from String to Integer.
private static String var1 = "debug";
private static Integer var1 = 666; However, in the following scenario, var1 will add data at runtime. If you overwrite it, you will lose the runtime data.
private static Map<String, Long> var1 = new HashMap<>();Therefore, DebugTools will overwrite runtime data by default, but you can prevent overwriting of field runtime data using the following method.
Method 1: Specify in the static code library that the variable should only be assigned a value when it is empty, such as:
private static Map<String, Long> var1;
static {
// This way, executing this code block when calling the clinit method will not overwrite runtime data.
if (var1 == null) {
var1 = new HashMap<>();
}
}Method 2: Configure in plugin
When the mouse hovers over a field, you can add configuration options via the right-click menu to ignore the field during hot reload, so that the runtime value is not overridden by the compile-time value. After adding, an icon will appear at the top of the line, and clicking it will remove the field from the ignore list.

Adding configuration options to the page allows users to write and switch between different configuration files.

The file content is a regular conf file; both class#fieldname and class.fieldname are acceptable, and comments are supported (# and ;).

Enumeration class information changes.
public enum StatusEnum {
A1,
A22,
A2,
A3,
}After the change, there are only two enumeration values, A2 and A3.
public enum StatusEnum {
A1(1, "a"),
A1(1, "A"),
A22(22, "BB"),
A2(2, "B"),
A3(3, "C"),
;
private final Integer code;
private final String name;
public StatusEnum(Integer code, String name) {
this.code = code;
this.name = name;
}
public Integer getCode() {
return code;
}
public String getName() {
return name;
}
public StatusEnum of(Integer code) {
for (StatusEnum statusEnum : StatusEnum.values()) {
if (statusEnum.getCode().equals(code)) {
return statusEnum;
}
}
return code;
}
}The content will take effect after being changed.
Internal class changes
public class UserVO {
private String userName;
private List<RoleVO> userRoles;
public static class RoleVO {
private Long roleId;
private String name;
private String roleName;
private Integer status;
public String getName() {
return name;
public String getRoleName() {
return roleName;
}
public String getStatusName() {
return status == 1 ? "正常" : "禁用";
}
}
private List<AuthVO> userAuths;
public class AuthVO {
private String authName;
}
}- Added
userAuthsattribute. - Modified
RoleVOinternal class information for normal use. - Added
AuthVOinternal class information for normal use.
Abstract class
Turn on hot reload, and when the abstract class is modified, all subclasses will take effect.
public abstract class User {
public String getUserName() {
return "default";
}
}
public class Debug extends User {
}
public class Tools extends User {
}After hot reloading User, both Debug and Tools can use the getUserName() method.
Interface
When the default method of an interface is modified, all implementation classes will take effect.
public interface User {
default String getUserName() {
return "default";
}
}
public class Debug implements User {
}
public class Tools implements User {
}After hot reloading User, both Debug and Tools can use the getUserName() method.