KANG's BLOG

Let's have some fun

优雅的使用AssertionError

如果确定该类不能被实例化,应当在私有构造方法中,增加AssertionError throw new AssertionError("No java.util.Objects instances for you!"); Java反射可以修改方法的访问权限,如果不抛出错误,使用Constructor.newInstance()方法仍可以实例化。 public class ClassPrivate { @Test public void test() { try { Class<?

(){}[]是否成对出现

String s = "(1){CHI[与|和] || CAT[J] LOGIC[G|D]}+(2){CAT[A] || OF_AMBI[A]}+(3){CHI[的]||CAT[N]}"; Stack<Character> sc = new Stack<Character>(); char[] c = s.

AOP日志

1. 为切面提供注解 /** * 打印日志 */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) public @interface OpenLog { /** * 方法说明 */ String value() default ""; } PS:另外提供@NoLogRequest和@NoLogResponse选择隐藏日志中的参数

bean的作用域

作用域 singleton 在spring IoC容器仅存在一个Bean实例,Bean以单例方式存在,默认值 prototype 每次从容器中调用Bean时,都返回一个新的实例,即每次调用getBean()时,相当于执行newXxxBean() request 每次HTTP请求都会创建一个新的Bean,该作用域仅适用于WebApplicationContext环境 session 同一个HTTP Session共享一个Bean,不同Session使用不同的Bean,仅适用于WebApplicationContext环境

HashMap的死循环问题

Hash的扩容方式 当HashMap中的元素个数超过数组大小(数组总大小length,不是数组中个数size)*loadFactor时,就会进行数组扩容 链表长度大于8或者数组长度小于64时转为红黑树 扩容为什么是2的幂次方 因为在计算元素该存放的位置的时候,用到的算法是将元素的hashcode与当前map长度-1进行与运算。源码: static int indexFor(int h, int length) { // assert Integer.

JS整型最大精度

JS整型最大精度 9007 1992 5474 0992 共16位

List.toArray()

List.toArray() 如果传入的数组长度大于集合长度,超出范围为null 如果小于长度,生成一个传入数组运行时类型的新的数组 public <T> T[] toArray(T[] a) { if (a.

Spring Boot热部署方式

Spring Boot热部署方式 POM添加引用,build后生效 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency> 配置文件中添加配置,防止build后自动重启 spring.devtools.restart.enabled=false

SpringBootServletInitializer

SpringBootServletInitializer springboot可以使用内置tomcat启动,也可以使用外部tomcat启动。 当需要依赖外部tomcat启动时,就不能依赖于Application的main函数了,而是要以类似于web.xml文件配置的方式来启动spring应用上下文,因此需要在启动类继承SpringBootServletInitializer并实现configure方法,这个类的作用与在web.xml中配置负责初始化spring应用上下文的监听器作用类似。

Spring配置文件beans中的xmlns

Spring配置文件beans中的xmlns <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.