illegal unquoted character_parallel scavenge

2022-05-10 13:41:42 浏览数 (2)

大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说illegal unquoted character_parallel scavenge,希望能够帮助大家进步!!!

代码语言:javascript复制
Person[name=Jack,age=10]
style==null:Person@deb6432[name=Jack,age=10,password=Jack'sPassword]
SHORT_PREFIX_STYLE:Person[name=Jack,age=10,password=Jack'sPassword]
SIMPLE_STYLE:Jack,10,Jack'sPassword
MULTI_LINE_STYLE:Person@deb6432[
  name=Jack
  age=10
  password=Jack'sPassword
]
NO_FIELD_NAMES_STYLE:Person@deb6432[Jack,10,Jack'sPassword]

只听到从架构师办公室传来架构君的声音:

海燕未来人斗草,江梅已过柳生绵。有谁来对上联或下联?

代码语言:javascript复制
此代码由Java架构师必看网-架构君整理
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.lang.reflect.Field;
import java.util.Objects;

public class StringUtilsDemo {
    public static void main(String[] args) {
        Person person = new Person();
        person.setName("Jack");
        person.setPassword("Jack'sPassword");
        person.setAge((short) 10);
        System.out.println(""   person);
        System.out.println("style==null:"   ReflectionToStringBuilder.toString(person));
        System.out.println("SHORT_PREFIX_STYLE:"   ReflectionToStringBuilder.toString(person, ToStringStyle.SHORT_PREFIX_STYLE));//截去了包名
        System.out.println("SIMPLE_STYLE:"   ReflectionToStringBuilder.toString(person, ToStringStyle.SIMPLE_STYLE));
        System.out.println("MULTI_LINE_STYLE:"   ReflectionToStringBuilder.toString(person, ToStringStyle.MULTI_LINE_STYLE));
        System.out.println("NO_FIELD_NAMES_STYLE:"   ReflectionToStringBuilder.toString(person, ToStringStyle.NO_FIELD_NAMES_STYLE));

    }
}

class Person {
    private String name;
    private Short age;
    private String password;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Short getAge() {
        return age;
    }

    public void setAge(Short age) {
        this.age = age;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) {
            @Override
            protected boolean accept(Field field) {
                return super.accept(field) && !Objects.equals(field.getName(), "password");
            }
        }.toString();
    }


}
代码语言:javascript复制
package org.test.InitializingBean;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 测试 spring的 InitializingBean 接口
 * @author Administrator
 *
 */
public class InitializingBeanTest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        
        ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml", 
                InitializingBeanTest.class);
        ctx.start();

    }

}
代码语言:javascript复制
此代码由Java架构师必看网-架构君整理
package org.test.InitializingBean;

import org.springframework.beans.factory.InitializingBean;

/**
 * @see {
    
    @link org.springframework.beans.factory.InitializingBean#afterPropertiesSet}
 * @author Administrator
 *
 */
public class User implements InitializingBean {

    public User() {
        System.out.println(">>>>>>> User 默认的构造函数执行了");
    }
        
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println(">>>>>>> 执行了 afterPropertiesSet 方法");

    }

}

执行的结果如下图所示。可以看到当执行完User默认的构造函数之后,就会调用该类实现afterPropertiesSet方法

0 人点赞