人生的意義在於修煉!修煉之路~
dracularking · 共 419 篇文章
NullPointerException in ternary operator
java代码: Integer i = null; Integer x = true ? i : 1; assembly code: public static void main(java.lang.String[]); Code: Stack=1, Locals=3, Args_size=1 0: aconst_null 1: astore_1 2: aload_1 3: invokevirtual #2; //Method java/lang/Integer.intValue:()I 6: invokestatic #3; //Method java/lang/Integer.valu…
2013-01-19 00:01 · 牛角钻尖 · 评论(0)
关于方法访问控制符protected
http://bbs.csdn.net/topics/390297526?page=1#post-393055530 所以总结下来,关于方法能否调用有两点: 1. 方法是否属于该对象,自身的方法和继承的方法都属于对象,这是能否调用的前提,解决了有没有的问题。 2. 该方法的访问控制符(access modifier)与当前调用地点是否满足访问控制符的要求,解决了见没见的问题。 比如楼主提到的情形,方法调用发生在包外,调用点所在类又没有继承方法声明时所在类,因此不可调用(原因是方法不可见,不是没有)。而此时,调用方法的实例是继承了方法所在类这一事实构成了混淆点,它是继承,但不是方法调用发生点所…
2012-11-29 10:38 · 经验记录 · 评论(0)
RuntimeException为啥不用声明抛出?
异常,错误都是同一种父类:java.lang.Throwable IllegalStateException属于RuntimeException,RuntimeException又是Exception的子类 RuntimeException的特点是非受检异常,区别于受检异常,也就是java系统允许可以不catch(当然也可以人为catch,比如特殊业务逻辑需要),在运行时碰到就抛出 关键RuntimeException为什么会被系统允许不被catch... 也就是可能会抛出RuntimeException的方法不被要求在方法throws clause中声明。 原因我想RuntimeExcep…
2012-11-13 15:04 · 问题交流 · 评论(0)
java语言中classes分类
local class的scope是local,所以在方法外不可见,这个三楼说过了。 这里有总结: A class defined within another class is called a nested class. Like other members of a class, a nested class can be declared static or not. A nonstatic nested class is called an inner class. An instance of an inner class can exist only within an ins…
2012-10-22 13:09 · 概念模式 · 评论(0)
effective java 2nd Item 18
Prefer interfaces to abstract classes 其中一段: Interfaces allow the construction of nonhierarchical type frameworks. Type hierarchies are great for organizing some things, but other things don’t fall neatly into a rigid hierarchy. For example, suppose we have an interface representing a singer and ano…
2012-08-15 15:45 · 读书天地 · 评论(0)
URL definition
http://reg.163.com/login.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2? lightweight=1 通用格式: protocol :// host / location 1. http://reg.163.com/ http 通信协议名称 :// 分隔符,一个用来表示协议定义的简单命名传统 reg.163.com 这是host,可以是DNS或IP,表示网络上的一台计算机或其它设备 / 分隔符 2. location部分包含了在host上一个特定网络资源的路径,这里就是login.jsp…
2012-08-14 08:29 · 概念模式 · 评论(0)
how to defend against serialization and reflection attack for eager singleton
//为什么要定义构造方法 因为不定义它也会有默认构造方法,而且是public的,不符合单例的设计模式要求 这种eager singleton是线程安全的,因为JVM保证了静态变量只由classloader初始化一次,也因此意味着所有调用getInstance的线程只能得到同一个变量实例 但是这种方法不足以保护其免遭reflection attack,因为反射可以改变私有变量的访问控制符 AccessibleObject.setAccessible(true),应对这种情况就需要这样: public class JavaSingleton { private static final Java…
2012-08-08 09:18 · 概念模式 · 评论(0)
Would
Would Would is an auxiliary verb, a modal auxiliary verb. We use would mainly to: talk about the past talk about the future in the past express the conditional mood We also use would for other functions, such as: expressing desire, polite requests and questions, opinion or hope, wish and regret... …
2012-07-06 12:10 · 英语研究 · 评论(0)
why null is allocated on java stack
提问: 恩。。。俺的意思是, String str = null; str = "String"; 最后的"String"对象是建立在栈里的,而不是堆里的,这样一来,第一句话,仍然还是在堆中开辟空间么?因为最后的对象其实是在栈中,如果一开始声明null的时候,在堆中开辟空间,岂不是有点奇怪? 回答: 1. null不是一个对象,JLS 3.10.7 中提及的是The Null Literal,况且它是ASCII中值为0的一个字符 2. null instanceof Object 是false 也证明了它不是Object 3. null在JVM全局内存中只存在一个,因为它无需存在多个,造成不…
2012-06-05 11:45 · 问题交流 · 评论(0)
Finalizer Guardian Idiom
Effective Java 2nd 中Item 7: Avoid finalizers關於Finalizer Guardian Idiom的論述: If a subclass implementor overrides a superclass finalizer but forgets to invoke it, the superclass finalizer will never be invoked. It is possible to defend against such a careless or malicious subclass at the cost of creat…
2012-05-30 11:55 · 概念模式 · 评论(0)
Cannot open connection
异常: Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) at org.hibernate.exception.JDBCEx…
2012-05-24 11:34 · 异常分析 · 评论(1)
我對多態的理解
多态(polymorphism)是以一种看待事物更细致的角度来描述事物(或者说以抓住了这种特质的独具慧眼的角度),事物多具有本质(共性),也有各种不同的变化形态(比如碳元素会有金刚石和石墨两种形态),各形态都有其独特作用,但是万变不离其宗,它们以共性相联,是基于这种独特而深刻的认识。 当要利用这种物体的各个形态时,有形态变化的物体,使用起来更灵活。比如你事先预估到自己要用到人形机器人来让他干精细活,和交通工具来代步。这时候如果你 想到的是变形金刚,可能对于你今后的使用要方便很多,一物重用且随时随地切换,使用灵活,当然代价是初始的设计比较麻烦。但如果你没想到要用变形金刚这种 多态的工具,而是分…
2012-05-24 09:03 · 概念模式 · 评论(0)
关于Java 泛型 ?extends T 的问题
http://topic.csdn.net/u/20120516/22/a19617f5-943e-494c-9595-1c049b1cc3ef.html?seed=208934876&r=78626688#r_78626688 问: 在学习java泛型时 ,看到了泛型的一个例子 List<Apple> apples = new ArrayList<Apple>(); List<? extends Fruit> fruits = apples; fruits.add(new Strawberry()); 其中,Fruit是父类、Apple和Strawberry是子类,add操作执行错误,给出…
2012-05-21 11:05 · 问题交流 · 评论(0)
一个基本问题关于引用的
问: int a = 1; Integer b = new Integer(1); System.out.println(a==b); 结果为什么是true 但是 String c = "abc"; String d = new String("abc"); System.out.println(c == d); 结果就是false了? 请说一下具体的原因 答: ==在java中的作用是比较,比较的是左右两个操作数的“直接值”,所谓直接值,对基本类型而言就是其值本身,比如int a = 1,就是1;对引用类型而言,就相当于“内存地址”,引用对象内部所包含的内容(比如String的字符串)不是…
2012-05-15 10:20 · 经验记录 · 评论(0)
Invalid byte x of n-byte UTF-8 sequence.
是在从客户端发来的SOAPMessage中getEnvelope时出了错 提示错误原因是:Invalid byte 1 of 1-byte UTF-8 sequence. 它解析到了在 1字节UTF-8序列中无效的第一字节 1字节UTF-8序列是怎么样的呢? One-byte codes are used only for the ASCII values 0 through 127. In this case the UTF-8 code has the same value as the ASCII code. The high-order bit of these codes is a…
2012-05-14 11:50 · 编解乱码 · 评论(0)