??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品超碰,国产精品日本,www.成人.comhttp://www.aygfsteel.com/lijun/java,javazh-cnTue, 17 Jun 2025 20:43:31 GMTTue, 17 Jun 2025 20:43:31 GMT60 veloeclipse eclipse 4.4不兼容该插ghttp://www.aygfsteel.com/lijun/archive/2014/08/21/417184.html键盘动物键盘动物Thu, 21 Aug 2014 03:24:00 GMThttp://www.aygfsteel.com/lijun/archive/2014/08/21/417184.htmlhttp://www.aygfsteel.com/lijun/comments/417184.htmlhttp://www.aygfsteel.com/lijun/archive/2014/08/21/417184.html#Feedback0http://www.aygfsteel.com/lijun/comments/commentRss/417184.htmlhttp://www.aygfsteel.com/lijun/services/trackbacks/417184.html//vm 模板
http://veloeclipse.googlecode.com/svn/trunk/update/
eclipse 4.4不兼容该插g
eclipse 4.4的vm新插Ӟhttp://plugin.tqlab.com/eclipse/velocityeditor/update/


键盘动物 2014-08-21 11:24 发表评论
]]>
老版本的jdk下蝲http://www.aygfsteel.com/lijun/archive/2014/08/21/417179.html键盘动物键盘动物Thu, 21 Aug 2014 01:52:00 GMThttp://www.aygfsteel.com/lijun/archive/2014/08/21/417179.htmlhttp://www.aygfsteel.com/lijun/comments/417179.htmlhttp://www.aygfsteel.com/lijun/archive/2014/08/21/417179.html#Feedback0http://www.aygfsteel.com/lijun/comments/commentRss/417179.htmlhttp://www.aygfsteel.com/lijun/services/trackbacks/417179.htmlhttp://www.oracle.com/technetwork/java/archive-139210.html

键盘动物 2014-08-21 09:52 发表评论
]]>
jvm之java源码~译机制http://www.aygfsteel.com/lijun/archive/2014/08/08/416748.html键盘动物键盘动物Fri, 08 Aug 2014 11:31:00 GMThttp://www.aygfsteel.com/lijun/archive/2014/08/08/416748.htmlhttp://www.aygfsteel.com/lijun/comments/416748.htmlhttp://www.aygfsteel.com/lijun/archive/2014/08/08/416748.html#Feedback0http://www.aygfsteel.com/lijun/comments/commentRss/416748.htmlhttp://www.aygfsteel.com/lijun/services/trackbacks/416748.html
javap -c  -s -l -verbose Foo


键盘动物 2014-08-08 19:31 发表评论
]]>
java 自动装箱与拆?引发的血?/title><link>http://www.aygfsteel.com/lijun/archive/2014/08/08/416736.html</link><dc:creator>键盘动物</dc:creator><author>键盘动物</author><pubDate>Fri, 08 Aug 2014 07:32:00 GMT</pubDate><guid>http://www.aygfsteel.com/lijun/archive/2014/08/08/416736.html</guid><wfw:comment>http://www.aygfsteel.com/lijun/comments/416736.html</wfw:comment><comments>http://www.aygfsteel.com/lijun/archive/2014/08/08/416736.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lijun/comments/commentRss/416736.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lijun/services/trackbacks/416736.html</trackback:ping><description><![CDATA[<span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; color: red; background-color: #f7fcff;">装箱Q从基本cd转换成ObjectcdQ称之ؓ装箱Q?/span><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; color: #339966; background-color: #f7fcff;">***拆箱Q从Object转换乘基本类型的操作Q称之ؓ拆箱?q个操作在反过E中用的比较的多?nbsp;</span><br style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #f7fcff;" /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; color: #ff0000; background-color: #f7fcff;">装箱Q在堆中建立一个Object实例Q把你指定的值复制成?/span><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #f7fcff;">Q?/span><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; color: #339966; background-color: #f7fcff;">***拆箱Q判别引用指向的堆中信息是否是要拆成的类型,是取出堆中值送给栈中变量Q否则报异常 </span><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #ddedfb;"><br />//?128~127 之外的数 </span><br style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px;" /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #ddedfb;">Integer num1 = 297; Integer num2 = 297; </span><br style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px;" /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #ddedfb;">System.out.println("num1==num2: "+(num1==num2)); </span><br style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px;" /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #ddedfb;">// ?128~127 之内的数 </span><br style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px;" /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #ddedfb;">Integer num3 = 97; Integer num4 = 97; </span><br style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px;" /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #ddedfb;">System.out.println("num3==num4: "+(num3==num4)); 打印的结果是Qnum1==num2: false num3==num4: true <br /></span><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #f7fcff;">很奇怪吧Q这归l于java对于Integer与int的自动装׃拆箱的设计,是一U模式:叫n元模式(flyweightQ?nbsp;</span><br style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #f7fcff;" /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; color: #ff0000; background-color: #f7fcff;">Z加大对简单数字的重利用,java定义Q在自动装箱时对于g–128?27之间的|它们被装׃ؓInteger对象后,会存在内存中被重用,始终只存在一个对?nbsp;</span><br style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #f7fcff;" /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; color: #339966; background-color: #f7fcff;"><strong>而如果超q了?#8211;128?27之间的|被装后的Integer对象q不会被重用Q即相当于每ơ装时都新Z?Integer对象Q?/strong></span><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #f7fcff;">明白了吧  </span><br style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #f7fcff;" /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #f7fcff;">以上的现象是׃使用了自动装所引v的,如果你没有用自动装,而是跟一般类一P用new来进行实例化Q就会每ơnew都一个新的对象; </span><br /><span style="font-family: Tahoma, Helvetica, Arial, 宋体, sans-serif; line-height: 25.200000762939453px; background-color: #ddedfb;"><br /></span><img src ="http://www.aygfsteel.com/lijun/aggbug/416736.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lijun/" target="_blank">键盘动物</a> 2014-08-08 15:32 <a href="http://www.aygfsteel.com/lijun/archive/2014/08/08/416736.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java泛型面试?/title><link>http://www.aygfsteel.com/lijun/archive/2014/08/08/416734.html</link><dc:creator>键盘动物</dc:creator><author>键盘动物</author><pubDate>Fri, 08 Aug 2014 07:14:00 GMT</pubDate><guid>http://www.aygfsteel.com/lijun/archive/2014/08/08/416734.html</guid><wfw:comment>http://www.aygfsteel.com/lijun/comments/416734.html</wfw:comment><comments>http://www.aygfsteel.com/lijun/archive/2014/08/08/416734.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lijun/comments/commentRss/416734.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lijun/services/trackbacks/416734.html</trackback:ping><description><![CDATA[<h2><br /></h2><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>1. Java中的泛型是什?? 使用泛型的好处是什?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  q是在各UJava泛型面试中,一开Z׃被问到的问题中的一个,主要集中在初U和中面试中。那些拥有Java1.4或更早版本的开发背景的人都知道Q?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">在集合中存储对象</a>q在使用前进行类型{换是多么的不方便。泛型防止了那种情况的发生。它提供了编译期的类型安全,保你只能把正确cd的对象放入集合中Q避免了在运行时出现ClassCastException?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>2. Java的泛型是如何工作?? 什么是cd擦除 ?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  q是一道更好的泛型面试题。泛型是通过cd擦除来实现的Q编译器在编译时擦除了所有类型相关的信息Q所以在q行时不存在Mcd相关的信息。例如List<String>在运行时仅用一?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">List</a>来表C。这样做的目的,是确保能和Java 5之前的版本开发二q制cdq行兼容。你无法在运行时讉K到类型参敎ͼ因ؓ~译器已l把泛型cd转换成了原始cd。根据你对这个泛型问题的回答情况Q你会得C些后l提问,比如Z么泛型是q型擦除来实现的或者给你展CZ些会D~译器出错的错误泛型代码。请阅读我的<a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">Java中泛型是如何工作?/a>来了解更多信息?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>3. 什么是泛型中的限定通配W和非限定通配W??</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  q是另一个非?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">行的Java泛型面试?/a>。限定通配W对cdq行了限制。有两种限定通配W,一U是<? extends T>它通过保cd必须是T的子cL讑֮cd的上界,另一U是<? super T>它通过保cd必须是T的父cL讑֮cd的下界。泛型类型必ȝ限定内的cd来进行初始化Q否则会D~译错误。另一斚w<?>表示了非限定通配W,因ؓ<?>可以用Q意类型来替代。更多信息请参阅我的文章<a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">泛型中限定通配W和非限定通配W之间的区别</a>?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>4. List<? extends T>和List <? super T>之间有什么区??</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  q和上一个面试题有联p,有时面试官会用这个问题来评估你对泛型的理解,而不是直接问你什么是限定通配W和非限定通配W。这两个List的声明都?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">限定通配W的例子</a>QList<? extends T>可以接受Ml承自T的类型的ListQ而List<? super T>可以接受MT的父cL成的List。例如List<? extends Number>可以接受List<Integer>或List<Float>。在本段出现的连接中可以扑ֈ更多信息?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>5. 如何~写一个泛型方法,让它能接受泛型参数ƈq回泛型cd?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  ~写泛型Ҏq不困难Q你需要用泛型cd来替代原始类型,比如使用T, E or K,V{被q泛认可的类型占位符。泛型方法的例子请参?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">Java集合cL?/a>。最单的情况下,一个泛型方法可能会像这?</p><pre style="margin-top: 8px; margin-bottom: 8px; padding: 8px; font-family: Arial; border: 1px solid #cccccc; color: #555555; line-height: 23.799999237060547px; background: #f3f3f3;">public V put(K key, V value) { return cache.put(key, value); } </pre><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>6. Java中如何用泛型编写带有参数的c?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  q是上一道面试题的g伸。面试官可能会要求你用泛型编写一个类型安全的c,而不是编写一个泛型方法。关键仍然是使用泛型cd来代替原始类型,而且要用JDK中采用的标准占位W?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>7. ~写一D|型程序来实现LRU~存?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  对于喜欢<a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">Java~程</a>的h来说q相当于是一ơ练习。给你个提示QLinkedHashMap可以用来实现固定大小的LRU~存Q当LRU~存已经满了的时候,它会把最老的键值对Ud~存。LinkedHashMap提供了一个称为removeEldestEntry()的方法,该方法会被put()和putAll()调用来删除最老的键值对。当Ӟ如果你已l编写了一个可q行?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">JUnit试</a>Q你也可以随意编写你自己的实C码?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>8. 你可以把List<String>传递给一个接受List<Object>参数的方法吗Q?/strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  对Q何一个不太熟悉泛型的人来_q个Java泛型题目看v来o人疑惑,因ؓ乍看hString是一UObjectQ所以List<String>应当可以用在需要List<Object>的地方,但是事实q如此。真q样做的话会D~译错误。如果你再深一步考虑Q你会发现Javaq样做是有意义的Q因为List<Object>可以存储Mcd的对象包?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">String, Integer</a>{等Q而List<String>却只能用来存储Strings?/p><pre style="margin-top: 8px; margin-bottom: 8px; padding: 8px; font-family: Arial; border: 1px solid #cccccc; color: #555555; line-height: 23.799999237060547px; background: #f3f3f3;">List<Object> objectList; List<String> stringList; objectList = stringList; //compilation error incompatible types</pre><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>9. Array中可以用泛型?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  q可能是Java泛型面试题中最单的一个了Q当然前提是你要知道Array事实上ƈ不支持泛型,q也是ؓ什么Joshua Bloch?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">Effective Java</a>一书中使用List来代替ArrayQ因为List可以提供~译期的cd安全保证Q而Array却不能?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>10. 如何LJava中的cd未检查的警告?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  如果你把泛型和原始类型؜合v来用,例如下列代码QJava 5的javac~译器会产生cd未检查的警告Q例?/p><pre style="margin-top: 8px; margin-bottom: 8px; padding: 8px; font-family: Arial; border: 1px solid #cccccc; color: #555555; line-height: 23.799999237060547px; background: #f3f3f3;">List<String> rawList = new ArrayList() 注意: Hello.java使用了未查或UCؓ不安全的操作; </pre><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  q种警告可以使用@SuppressWarnings("unchecked")注解来屏蔽?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>Java泛型面试题补充更?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  我手头又拿到了几个Java泛型面试题跟大家分n下,q几道题集中在泛型类型和原始cd的区别上Q以及我们是否可以用Object来代曉K定通配W的使用{等Q?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>Java中List<Object>和原始类型List之间的区?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  原始cd和带参数cd<Object>之间的主要区别是Q在~译?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">~译?/a>不会对原始类型进行类型安全检查,却会对带参数的类型进行检查,通过使用Object作ؓcdQ可以告知编译器该方法可以接受Q何类型的对象Q比如String或Integer。这道题的考察点在于对泛型中原始类型的正确理解。它们之间的W二点区别是Q你可以把Q何带参数的类型传递给原始cdListQ但却不能把List<String>传递给接受List<Object>的方法,因ؓ会生变异错误。更多详l信息请参阅<a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">Java中的泛型是如何工作的</a>?/p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>Java中List<?>和List<Object>之间的区别是什?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  q道题跟上一道题看v来很像,实质上却完全不同。List<?> 是一个未知类型的ListQ而List<Object>其实是Q意类型的List。你可以把List<String>, List<Integer>赋值给List<?>Q却不能把List<String>赋值给List<Object>?nbsp;    </p><pre style="margin-top: 8px; margin-bottom: 8px; padding: 8px; font-family: Arial; border: 1px solid #cccccc; color: #555555; line-height: 23.799999237060547px; background: #f3f3f3;">List<?> listOfAnyType; List<Object> listOfObject = new ArrayList<Object>(); List<String> listOfString = new ArrayList<String>(); List<Integer> listOfInteger = new ArrayList<Integer>(); listOfAnyType = listOfString; //legal listOfAnyType = listOfInteger; //legal listOfObjectType = (List<Object>) listOfString; //compiler error - in-convertible types </pre><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  想了解更多关于通配W的信息h?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">Java中的泛型通配W示?/a></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  <strong>List<String>和原始类型List之间的区?</strong></p><p style="margin: 10px 0px; padding: 0px; color: #555555; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23.799999237060547px; background-color: #f9f9f9;">  该题cM?#8220;原始cd和带参数cd之间有什么区?#8221;。带参数cd是类型安全的Q而且其类型安全是q译器保证的,?a rel="nofollow" style="color: #0d4ac6; text-decoration: none;">原始cdList却不是类型安全的</a>。你不能把String之外的Q何其它类型的Object存入Stringcd的List中,而你可以把Q何类型的对象存入原始List中。用泛型的带参数类型你不需要进行类型{换,但是对于原始cdQ你则需要进行显式的cd转换?/p><pre style="margin-top: 8px; margin-bottom: 8px; padding: 8px; font-family: Arial; border: 1px solid #cccccc; color: #555555; line-height: 23.799999237060547px; background: #f3f3f3;">List listOfRawTypes = new ArrayList(); listOfRawTypes.add("abc"); listOfRawTypes.add(123); //~译器允许这?- q行时却会出现异?String item = (String) listOfRawTypes.get(0); //需要显式的cd转换 item = (String) listOfRawTypes.get(1); //抛ClassCastExceptionQ因为Integer不能被{换ؓString List<String> listOfString = new ArrayList(); listOfString.add("abcd"); listOfString.add(1234); //~译错误Q比在运行时抛异常要?item = listOfString.get(0); //不需要显式的cd转换 - ~译器自动{?</pre><img src ="http://www.aygfsteel.com/lijun/aggbug/416734.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lijun/" target="_blank">键盘动物</a> 2014-08-08 15:14 <a href="http://www.aygfsteel.com/lijun/archive/2014/08/08/416734.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>泛型的好?/title><link>http://www.aygfsteel.com/lijun/archive/2014/08/08/416730.html</link><dc:creator>键盘动物</dc:creator><author>键盘动物</author><pubDate>Fri, 08 Aug 2014 06:57:00 GMT</pubDate><guid>http://www.aygfsteel.com/lijun/archive/2014/08/08/416730.html</guid><wfw:comment>http://www.aygfsteel.com/lijun/comments/416730.html</wfw:comment><comments>http://www.aygfsteel.com/lijun/archive/2014/08/08/416730.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lijun/comments/commentRss/416730.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lijun/services/trackbacks/416730.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">Java 语言中引入泛型是一个较大的功能增强。不仅语a、类型系l和~译器有了较大的变化Q以支持泛型Q而且cd也进行了大翻修,所以许多重要的c,比如集合框架Q都已经成ؓ泛型化的了?/p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">q带来了很多好处Q?br /><br /><strong>1Q类型安全?/strong> 泛型的主要目标是提高 Java E序的类型安全。通过知道使用泛型定义的变量的cd限制Q编译器可以在一个高得多的程度上验证cd假设。没有泛型,q些假设只存在于程序员的头脑中Q或者如果幸q的话,q存在于代码注释中)?/p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><strong>2Q消除强制类型{换?/strong> 泛型的一个附带好处是Q消除源代码中的许多强制cd转换。这使得代码更加可读Qƈ且减了出错Z?/p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"><strong>3Q潜在的性能收益?/strong> 泛型大的优化带来可能。在泛型的初始实CQ编译器强制类型{换(没有泛型的话Q程序员会指定这些强制类型{换)插入生成的字节码中。但是更多类型信息可用于~译器这一事实Qؓ未来版本?JVM 的优化带来可能。由于泛型的实现方式Q支持泛型(几乎Q不需?JVM 或类文g更改。所有工作都在编译器中完成,~译器生成类g没有泛型Q和强制cd转换Q时所写的代码Q只是更能确保类型安全而已?/p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;"> Java语言引入泛型的好处是安全单。泛型的好处是在~译的时候检查类型安全,q且所有的强制转换都是自动和隐式的Q提高代码的重用率?/p><p style="margin: 0px; padding: 0px; font-family: Arial; line-height: 26px; background-color: #ffffff;">    泛型在用中q有一些规则和限制Q?br />    1、泛型的cd参数只能是类cdQ包括自定义c)Q不能是单类型?br />    2、同一U泛型可以对应多个版本(因ؓ参数cd是不定的)Q不同版本的泛型cd例是不兼容的?br />    3、泛型的cd参数可以有多个?br />    4、泛型的参数cd可以使用extends语句Q例?lt;T extends superclass>。习惯上成ؓ“有界cd”?br />    5、泛型的参数cdq可以是通配W类型。例如Class<?> classType = Class.forName(Java.lang.String);</p><img src ="http://www.aygfsteel.com/lijun/aggbug/416730.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lijun/" target="_blank">键盘动物</a> 2014-08-08 14:57 <a href="http://www.aygfsteel.com/lijun/archive/2014/08/08/416730.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java 重写和重载的规则http://www.aygfsteel.com/lijun/archive/2014/08/08/416729.html键盘动物键盘动物Fri, 08 Aug 2014 06:44:00 GMThttp://www.aygfsteel.com/lijun/archive/2014/08/08/416729.htmlhttp://www.aygfsteel.com/lijun/comments/416729.htmlhttp://www.aygfsteel.com/lijun/archive/2014/08/08/416729.html#Feedback0http://www.aygfsteel.com/lijun/comments/commentRss/416729.htmlhttp://www.aygfsteel.com/lijun/services/trackbacks/416729.html重写Ҏ的规?/span>Q?/span>

1、参数列表必d全与被重写的Ҏ相同Q否则不能称其ؓ重写而是重蝲?/span>

2、返回的cd必须一直与被重写的Ҏ的返回类型相同,否则不能U其为重写而是重蝲?/span>

3、访问修饰符的限制一定要大于被重写方法的讉K修饰W(public>protected>default>privateQ?/span>

4、重写方法一定不能抛出新的检查异常或者比被重写方法申明更加宽泛的查型异常。例如:

父类的一个方法申明了一个检查异常IOExceptionQ在重写q个Ҏ是就不能抛出Exception,只能抛出IOException的子cd常,可以抛出非检查异常?/span>

 

而重载的规则Q?/span>

1、必d有不同的参数列表Q?/span>

2、可以有不责骂的q回cdQ只要参数列表不同就可以了;

3、可以有不同的访问修饰符Q?/span>

4、可以抛Z同的异常Q?/span>

 

重写与重载的区别在于Q?/span>

重写多态性v作用Q对调用被重载过的方法可以大大减代码的输入量,同一个方法名只要往里面传递不同的参数可以拥有不同的功能或返回倹{?/span>

用好重写和重载可以设计一个结构清晰而简z的c,可以说重写和重蝲在编写代码过E中的作用非同一?



键盘动物 2014-08-08 14:44 发表评论
]]>
java 泛型使用 擦除?/title><link>http://www.aygfsteel.com/lijun/archive/2014/08/08/416728.html</link><dc:creator>键盘动物</dc:creator><author>键盘动物</author><pubDate>Fri, 08 Aug 2014 06:38:00 GMT</pubDate><guid>http://www.aygfsteel.com/lijun/archive/2014/08/08/416728.html</guid><wfw:comment>http://www.aygfsteel.com/lijun/comments/416728.html</wfw:comment><comments>http://www.aygfsteel.com/lijun/archive/2014/08/08/416728.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lijun/comments/commentRss/416728.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lijun/services/trackbacks/416728.html</trackback:ping><description><![CDATA[<span style="font-family: 'Microsoft YaHei', Arial, Verdana, sans-serif; line-height: 19.600000381469727px; text-align: justify; background-color: #eeeeee;">擦除法ƈ不代表编译后的字节码中就不包含我们在源代码定义的泛型cd了。而是在字节码中引入新属性Signature ?LocalVariableTypeTable 来存储泛型。这也是Z么可以通过q回值重载,及通过反射获取到泛型的Ҏ原因</span><img src ="http://www.aygfsteel.com/lijun/aggbug/416728.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lijun/" target="_blank">键盘动物</a> 2014-08-08 14:38 <a href="http://www.aygfsteel.com/lijun/archive/2014/08/08/416728.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Collections.synchronizedMap(new HashMap())q个Ҏ是什么意?/title><link>http://www.aygfsteel.com/lijun/archive/2014/08/07/416687.html</link><dc:creator>键盘动物</dc:creator><author>键盘动物</author><pubDate>Thu, 07 Aug 2014 08:40:00 GMT</pubDate><guid>http://www.aygfsteel.com/lijun/archive/2014/08/07/416687.html</guid><wfw:comment>http://www.aygfsteel.com/lijun/comments/416687.html</wfw:comment><comments>http://www.aygfsteel.com/lijun/archive/2014/08/07/416687.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lijun/comments/commentRss/416687.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lijun/services/trackbacks/416687.html</trackback:ping><description><![CDATA[<span style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;">Collections.synchronizedMap是个比较老的API了,实际用v来还要手工做一些事?/span><br style="box-sizing: content-box; color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;" /><br style="box-sizing: content-box; color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;" /><span style="color: #333333; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 24px; background-color: #f5f5f5;">g用Java5的ConcurrentHashMap或Java6的ConcurrentSkipListMap</span><img src ="http://www.aygfsteel.com/lijun/aggbug/416687.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lijun/" target="_blank">键盘动物</a> 2014-08-07 16:40 <a href="http://www.aygfsteel.com/lijun/archive/2014/08/07/416687.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eclipse中关联jar出现qhttp://www.aygfsteel.com/lijun/archive/2014/07/31/416408.html键盘动物键盘动物Thu, 31 Jul 2014 07:31:00 GMThttp://www.aygfsteel.com/lijun/archive/2014/07/31/416408.htmlhttp://www.aygfsteel.com/lijun/comments/416408.htmlhttp://www.aygfsteel.com/lijun/archive/2014/07/31/416408.html#Feedback0http://www.aygfsteel.com/lijun/comments/commentRss/416408.htmlhttp://www.aygfsteel.com/lijun/services/trackbacks/416408.html1、首先要清楚源码的编码方式是什么?

如果源码的编码是utf-8 需要这样修?/span>

Preferences General > Workspace 修改Text file encoding

为UTF-8后才行?/span>

重新启动Eclipse可以解决了()

键盘动物 2014-07-31 15:31 发表评论
]]>
վ֩ģ壺 | | | | | | ȫ| | ͸| ϲ| Ϸ| Ľ| | ʤ| Ԫ| | ߰| ½| | | ³ƶ| | ɽ| ˷| Ӫɽ| | ȫ| Թ| ţ| ξ| | ͩ| | ͷ| | «Ϫ| ɽ| | ƽɽ| IJ| |