Bug JDK little you know about it?

JDK took such a long time, and there is no iron found in old JDK bug in it? From the earliest version of JDK1.2 now gaining in popularity since JDK1.8, JAVA gone through so many years of ups and downs, still insist on the line, is not feeling very amazing, but there are not many people take the initiative to see JDK source code? And you write the code is compiled out of the class class, how many brothers there to see the contents of it?

Before the company boss let me add a little function, and then compiled into class categories, I find that the code and I wrote does not even like people that do typesetting, the word "perfect." So whim to see if there any JDK BUG to make us some fun, so he wrote such an article to write their feelings and experiences!

 

Interest in, and this has continued to desire, and I began to check the information and to manually do the test here we take a look at some of these are summarized some small BUG exists in our development of it.

 

JDK array of cutting Bug1-- 

 

String split, we have used it, split this method we should all be familiar with, but there is no one tried to split this time to cut through the point of what problems it?

We do a test specific code is as follows:

 

 

In our minds in the printed results must be 3, but the actual situation and we think is completely not the same,

 

 

Print the result is 0, but the same situation we use other symbols to cut it?

 

 

The result is print and our memory is completely consistent with the results.

 

 

Print the result is three, this is a bug JDK, I do not know why he is so unique to the point, is it a traditional preference?

 

So here remind you to do the development of a small partner, when we use the split string, try not to go to the point of use, that is. "" Otherwise, you will find that sometimes a long time to write the code yourself actually I do not know turned out to be wrong because a small Bug JDK caused by, at that time estimated that you want to have the heart to kill Gosling. Of course, I'm using now the most used JDK1.8, if later versions of JDK1.8, this repair, then I can give you big brother reminder also become, thanks!

 

 The ternary operator JDK Bug2--

 

Basic data types of the ternary operator is assigned to Null, the editor is not being given to us, but when the program is running error occurs, we look at the code shows

 

 

 

在我们编辑代码的时候是一点不出错,但是当我们条件成立的时候就会有这种错误。

 

 

   其实这个错误很容易理解,为什么呢?三元运算符,哪有这么搞得,很少会出现这种不符合常理的错误,这只能说写代码的兄弟思路很开阔,但是也不排除会有这种情况的出现。所以得长点心,不能瞎搞不是?

 

JDK中不算Bug的Bug--ArrayList可通过构造函数传入非指定泛型的List并在get时出错

 

为什么标题会写不算Bug的Bug呢?因为这个比上面的还离谱。这是网上的网友发现的。

 

我们可以先看看代码展示

 

 

 

    JSONArray arr = new JSONArray(); //com.alibaba.fastjson.JSONArray    arr.add("s");    List<Long> list = new ArrayList<>(arr);     list.get(0); //Exception cannot cast String to Long

 

 

在看到这段代码的第一时间,我就想弄死这个写代码的兄弟,你前面的泛型和后边的传入的非指定的这种,好像没有人会这么写吧,不过后来想了一下,也不能弄死人家不是,这代码确实不报错呀!想来想去,还是觉得兄弟你有理,这个确实属于一个Bug,但是这是写代码的人不怎么会遇到的错误问题。所以我把它放到了第三个。

 

总结

 

总结起来其实蛮简单的,JDK我们用了这么多年,毕竟也算是稳定的很,作为一个开发者,要去尝试一下这些好玩的东西,说不定什么时候就能自己模仿出一个JDK来也说不定不是,所以Bug很多时候都是自己写出来的,作为一个合格的开发者要把自己的代码写的简单,逻辑严谨,少出一些笑话,实现功能就可以了。

 

希望各位干程序员的老铁们,继续一直坚持下去。

 

Java 极客技术公众号,是由一群热爱 Java 开发的技术人组建成立,专注分享原创、高质量的 Java 文章。如果您觉得我们的文章还不错,请帮忙赞赏、在看、转发支持,鼓励我们分享出更好的文章。

关注公众号,大家可以在公众号后台回复“博客园”,免费获得作者 Java 知识体系/面试必看资料。

 

Guess you like

Origin www.cnblogs.com/justdojava/p/11211606.html