Skip to content

Hot reload of normal class files

Property changes

java
public class User {
    
    private String userId; 
    
    private String name; 
    private String userName; 
    
    private Integer userAge; 
}
  • You can use the new userId attribute.
  • Remove the name attribute, and use the new userName attribute.
  • You can use the new userAge attribute.

Method changes

java
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 getUserName method.
  • Remove the getUserDefaultUser method, and use the new genDefaultUser method.

Static information changes

Support static variables, static final variables, and static code blocks.

java
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.

Enumeration class information changes.

java
public enum StatusEnum {
    
    A1, 
    A22, 
    A2, 
    A3, 
}

After the change, there are only two enumeration values, A2 and A3.

java
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

java
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 userAuths attribute.
  • Modified RoleVO internal class information for normal use.
  • Added AuthVO internal class information for normal use.

Abstract class

Turn on hot reload, and when the abstract class is modified, all subclasses will take effect.

java
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.

java
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.