原文转自Anthony_tester再次感谢大神的分享。
这篇文章介绍在Eclipse上面如何查看JDK源码,如果你用过Python下的Pycharm这个IDE,你会发现,它没有Eclipse好用,就光查看源码这个功能来讲,确实没有eclipse好使。那么问题来了,你知道在eclipse上如何查看JDK源码吗,你是否做过这样操作。我们都知道,在我们学习Java过程中,遇到很多不明白的类或者方法,我们就想通过阅读查看对应JDK源码去学习和理解这个方法的实现原理。
1. Eclipse上如何查看相关方法的源码
例如上面这个打印语句,我想看看println()这个方法的源码,具体步骤是这样的:鼠标悬停在println上方,然后按下键盘ctrl键,你会发现println下会出现一个下划线,鼠标点击就发生跳转。如果没有配置源码文件来源,就会出现source not found的页面。
看到上面提示“you can attach the fource by cicking Attach Source belows”,那么添加什么文件呢?
2. 如何解决source not found的问题
点击Attach Source..,选择你电脑安装jdk路径下的一个src.zip包就可以。
再次回到打印这句代码,试试鼠标悬停在println上面,按下ctrl和点击下划线,看看效果
到这里,如何查看源码和如何设置源码文件就介绍完了,你可以通过这种方法去查看你想学习相关JAVA中方法或者类的实现原理。通过阅读JDK源码,有助于你的编程能力提高和养成想JDK开发人员那样标准的代码规范。
<li class="tool-item tool-active is-like eye-protector-processed" style="transition: background-color 0.3s ease 0s; background-color: rgb(193, 230, 198);"><a href="javascript:;"><svg class="icon" aria-hidden="true"> <use xlink:href="#csdnc-thumbsup"></use> </svg><span class="name">点赞</span> <span class="count">8</span> </a></li> <li class="tool-item tool-active is-collection eye-protector-processed" style="transition: background-color 0.3s ease 0s; background-color: rgb(193, 230, 198);"><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true"> <use xlink:href="#icon-csdnc-Collection-G"></use> </svg><span class="name">收藏</span></a></li> <li class="tool-item tool-active is-share eye-protector-processed" style="transition: background-color 0.3s ease 0s; background-color: rgb(193, 230, 198);"><a href="javascript:;"><svg class="icon" aria-hidden="true"> <use xlink:href="#icon-csdnc-fenxiang"></use> </svg>分享</a></li> <!--打赏开始--> <!--打赏结束--> <li class="tool-item tool-more"> <a> <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg> </a> <ul class="more-box eye-protector-processed" style="transition: background-color 0.3s ease 0s; border-color: rgba(0, 0, 0, 0.35); background-color: rgb(193, 230, 198);"> <li class="item"><a class="article-report">文章举报</a></li> </ul> </li> </ul> </div> </div> <div class="person-messagebox eye-protector-processed" style="border-top-color: rgba(0, 0, 0, 0.35);"> <div class="left-message"><a href="https://blog.csdn.net/u011541946"> <img src="https://profile.csdnimg.cn/E/5/F/3_u011541946" class="avatar_pic" username="u011541946"> <img src="https://g.csdnimg.cn/static/user-reg-year/1x/6.png" class="user-years"> </a></div> <div class="middle-message"> <div class="title"><span class="tit"><a href="https://blog.csdn.net/u011541946" data-report-click="{"mod":"popu_379"}" target="_blank">Anthony_tester</a></span> </div> <div class="text"><span>发布了1007 篇原创文章</span> · <span>获赞 2050</span> · <span>访问量 334万+</span></div> </div> <div class="right-message"> <a href="https://bbs.csdn.net/topics/395532026" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-messageboard eye-protector-processed" style="transition: background-color 0.3s ease 0s; background-color: rgb(193, 230, 198);">他的留言板 </a> <a class="btn btn-sm attented bt-button personal-watch eye-protector-processed" data-report-click="{"mod":"popu_379"}" style="transition: background-color 0.3s ease 0s; border-color: rgba(0, 0, 0, 0.35); color: rgb(0, 0, 0); background-color: rgb(193, 230, 198);">已关注</a> </div> </div> </div>