OVal

Hibernate Validator method or constructor validation

房东的猫 提交于 2019-12-01 12:00:58
How can I use Hibernate validator to validate the arguments inside the constructor or method? I want the validation to occur before the ValueObject creation so I can throw an exception and not create the object unless all parameters are valid. Basically I'm trying to use annotations instead of doing something like this if possible: public class ConditionalPerson { private String name; private String surname; private int age; public ConditionalPerson(String name, String surname, int age){ if (name == null || surname == null || age < 1) { throw new IllegalArgumentException(); } this.name = name;

Hibernate Validator method or constructor validation

≡放荡痞女 提交于 2019-12-01 10:52:17
问题 How can I use Hibernate validator to validate the arguments inside the constructor or method? I want the validation to occur before the ValueObject creation so I can throw an exception and not create the object unless all parameters are valid. Basically I'm trying to use annotations instead of doing something like this if possible: public class ConditionalPerson { private String name; private String surname; private int age; public ConditionalPerson(String name, String surname, int age){ if

Integer面试连环炮以及源码分析

五迷三道 提交于 2019-11-27 07:19:47
场景:   昨天有位朋友去面试,我问他面试问了哪些问题,其中问了Integer相关的问题,以下就是面试官问的问题,还有一些是我对此做了扩展。 问:两个new Integer 128相等吗? 答:不。因为Integer缓存池默认是-127-128; 问:可以修改Integer缓存池范围吗?如何修改? 答:可以。使用 -Djava.lang.Integer.IntegerCache.high=300 设置Integer缓存池大小 问:Integer缓存机制使用了哪种设计模式? 答:亨元模式; 问:Integer是如何获取你设置的缓存池大小? 答: sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high"); 问: sun.misc.VM.getSavedProperty 和 System.getProperty 有啥区别? 答:唯一的区别是, System.getProperty 只能获取非内部的配置信息;例如 java.lang.Integer.IntegerCache.high 、 sun.zip.disableMemoryMapping 、 sun.java.launcher.diag 、 sun.cds.enableSharedLookupCache 等不能获取,这些只能使用 sun.misc.VM