1、Java数组声明
曾经一直以为数组声明只有String[] s1;这种格式,但还有另一种格式:String s2[],这两种格式效果是一样的,只是java语法糖的作用效果。如下两种数组声明格式:
String[] s1 = { "1", "2" }; String s2[] = { "1", "2" };
使用javap查看生成的字节码是一样的:
public static void main(java.lang.String[]) throws java.lang.Exception; Code: Stack=4, Locals=3, Args_size=1 0: iconst_2 1: anewarray #2; //class java/lang/String 4: dup 5: iconst_0 6: ldc #3; //String 1 8: aastore 9: dup 10: iconst_1 11: ldc #4; //String 2 13: aastore 14: astore_1 15: iconst_2 16: anewarray #2; //class java/lang/String 19: dup 20: iconst_0 21: ldc #3; //String 1 23: aastore 24: dup 25: iconst_1 26: ldc #4; //String 2 28: aastore 29: astore_2 30: return LineNumberTable: line 20: 0 line 21: 15 line 22: 30 Exceptions: throws java.lang.Exception }
2、Java泛型的本质
曾经以为Java泛型跟C#泛型一样...
C#泛型在类在编译时,先生成中间代码IL,通用类型T只是一个占位符。在实例化类时,根据用户指定的数据类 型代替T并由即时编译器(JIT)生成本地代码,这个本地代码中已经使用了实际的数据类型,等同于用实际类型写的类。C#里面的泛型无论是在程序的源代码 中、编译后的IL中、还是运行时的CLR中都是切实存在的,List<Integer>与List<String>就是两个不同的泛型,它们在系统运行期生成,有自己的虚方法表和类型数据,这种实现称为类型膨胀,是真实的泛型。
3、SQL_NO_CACHE
之前一直以为SQL_NO_CACHE是查询不走缓存,但并非如此,不是查询结果不从缓存里取,
而是查询的结果不放到缓存里,下面是MySQL文档(5.0,5.1,5.5都一样):
8.6.3.2. Query Cache SELECT Options Two query cache-related options may be specified in SELECT statements: SQL_CACHE The query result is cached if it is cacheable and the value of the query_cache_type system variable is ON or DEMAND. SQL_NO_CACHE The query result is not cached. Examples: SELECT SQL_CACHE id, name FROM customer; SELECT SQL_NO_CACHE id, name FROM customer;