Spring-Boot框架Record类型静态方法构造方法的测试------Spring-Boot框架

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.powernode.Pk1;

import java.util.Optional;

public record Student(Integer id, String name, String email, Integer age) {
    public Student(Integer id, String name, String email, Integer age) {
        System.out.println(id);
        if (id < 1) {
            throw new RuntimeException("id小于1");
        } else {
            this.id = id;
            this.name = name;
            this.email = email;
            this.age = age;
        }
    }

    public Student(Integer id, String name) {
        this(id, name, (String)null, (Integer)null);
    }

    public String concat() {
        return String.format(this.name + this.age);
    }

    public static String emailToUpperCase(String email) {
        return ((String)Optional.ofNullable(email).orElse("no Email")).toUpperCase();
    }

    public Integer id() {
        return this.id;
    }

    public String name() {
        return this.name;
    }

    public String email() {
        return this.email;
    }

    public Integer age() {
        return this.age;
    }
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.powernode.Pk1;

import java.util.Optional;

public record Student(Integer id, String name, String email, Integer age) {
    public Student(Integer id, String name, String email, Integer age) {
        System.out.println(id);
        if (id < 1) {
            throw new RuntimeException("id小于1");
        } else {
            this.id = id;
            this.name = name;
            this.email = email;
            this.age = age;
        }
    }

    public Student(Integer id, String name) {
        this(id, name, (String)null, (Integer)null);
    }

    public String concat() {
        return String.format(this.name + this.age);
    }

    public static String emailToUpperCase(String email) {
        return ((String)Optional.ofNullable(email).orElse("no Email")).toUpperCase();
    }

    public Integer id() {
        return this.id;
    }

    public String name() {
        return this.name;
    }

    public String email() {
        return this.email;
    }

    public Integer age() {
        return this.age;
    }
}
package com.powernode.Pk1;

import java.util.Optional;

public record Student(Integer id, String name, String email, Integer age) {
    public String concat(){
        return String.format(this.name+this.age);
    }
    public static String emailToUpperCase(String email){
        return Optional.ofNullable(email).orElse("no Email").toUpperCase();
    }
//    会执行这个紧凑型构造方法
    public Student{
        System.out.println(id);
        if(id < 1){
            throw new RuntimeException("id小于1");
        }
    }
//    再执行这个构造方法
    public Student(Integer id,String name){
        this(id,name,null,null);
    }
}
package com.powernode.Pk1;

import java.util.Optional;

public record Student(Integer id, String name, String email, Integer age) {
    public String concat(){
        return String.format(this.name+this.age);
    }
    public static String emailToUpperCase(String email){
        return Optional.ofNullable(email).orElse("no Email").toUpperCase();
    }
//    会执行这个紧凑型构造方法
    public Student{
        System.out.println(id);
        if(id < 1){
            throw new RuntimeException("id小于1");
        }
    }
//    再执行这个构造方法
    public Student(Integer id,String name){
        this(id,name,null,null);
    }
}

  4.0.0

  com.powernode
  Feature
  1.0-SNAPSHOT
  jar

  Feature
  http://maven.apache.org

  
    UTF-8
  

  
    
      junit
      junit
      4.13.2
      test
    
  
  
    
      
        org.apache.maven.plugins
        maven-compiler-plugin
        3.11.0
        
          17
          17
        
      
    
  


  4.0.0

  com.powernode
  Feature
  1.0-SNAPSHOT
  jar

  Feature
  http://maven.apache.org

  
    UTF-8
  

  
    
      junit
      junit
      4.13.2
      test
    
  
  
    
      
        org.apache.maven.plugins
        maven-compiler-plugin
        3.11.0
        
          17
          17
        
      
    
  

package com.powernode;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}
package com.powernode;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}
package com.powernode;

import com.powernode.Pk1.Student;
import org.junit.Test;

/**
 * Unit test for simple App.
 */
public class StudentTest {
    @Test
    public void Test01(){
//        创建Record对象
//        这里也会先执行紧凑的构造方法
        Student Rose = new Student(1001,"Rose","abc",15);
        System.out.println(Rose.toString());
        Integer age = Rose.age();
        System.out.println(age);
        String name = Rose.name();
        System.out.println(name);
        String email = Rose.email();
        System.out.println(email);
        System.out.println("哈哈");
        System.out.println(Rose.concat());
        System.out.println(Student.emailToUpperCase("Dasd"));
        Student jack = new Student(2001, "Jack");
        System.out.println(jack);
    }
}
package com.powernode;

import com.powernode.Pk1.Student;
import org.junit.Test;

/**
 * Unit test for simple App.
 */
public class StudentTest {
    @Test
    public void Test01(){
//        创建Record对象
//        这里也会先执行紧凑的构造方法
        Student Rose = new Student(1001,"Rose","abc",15);
        System.out.println(Rose.toString());
        Integer age = Rose.age();
        System.out.println(age);
        String name = Rose.name();
        System.out.println(name);
        String email = Rose.email();
        System.out.println(email);
        System.out.println("哈哈");
        System.out.println(Rose.concat());
        System.out.println(Student.emailToUpperCase("Dasd"));
        Student jack = new Student(2001, "Jack");
        System.out.println(jack);
    }
}

你可能感兴趣的:(JAVA,#,Spring框架,#,Spring-Boot框架,java,java-ee,spring,boot,spring,maven,xml,后端)