Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

类加载器一问的补充说明Java->JVM->6.类加载器 #871

Closed
ZerahMu opened this issue Jul 28, 2020 · 4 comments
Closed

类加载器一问的补充说明Java->JVM->6.类加载器 #871

ZerahMu opened this issue Jul 28, 2020 · 4 comments
Labels
enhancement New feature or request or suggestion typo Correct typos

Comments

@ZerahMu
Copy link

ZerahMu commented Jul 28, 2020

如果我们不想用双亲委派模型怎么办?
不想使用双亲委派模型,我们可以自定义自己的类加载器,需要继承 java.lang.ClassLoader,但是如果是要自定类加载器,也是需要继承ClassLoader,但是覆盖的是findClass方法,这点需要做下补充说明,这点看源码就可以确认,可以参考博客:https://blog.csdn.net/SEU_Calvin/article/details/52315125,因为最近面试经常被问到,之前被误导了,面试官反复确认,我还是说是重写`loadClass`方法,因而这点感觉需要做下补充说明。

@pHraySc
Copy link

pHraySc commented Jul 28, 2020 via email

@ZerahMu
Copy link
Author

ZerahMu commented Jul 29, 2020

不想用双亲委派模型肯定不是覆盖findClass方法呀,覆盖这个方法就等于默认使用双亲委派模型。 在 2020-07-28 16:41:48,"Zerah" notifications@github.com 写道: 如果我们不想用双亲委派模型怎么办? 不想使用双亲委派模型,我们可以自定义自己的类加载器,需要继承 java.lang.ClassLoader,但是如果是要自定类加载器,也是需要继承ClassLoader,但是覆盖的是findClass方法,这点需要做下补充说明,这点看源码就可以确认,可以参考博客:https://blog.csdn.net/SEU_Calvin/article/details/52315125,因为最近面试经常被问到,之前被误导了,面试官反复确认,我还是说是重写loadClass方法,因而这点感觉需要做下补充说明。 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

没问题的,就是可能之前我没表述清楚,我想表达的是:之前楼主没有对这个情况做区分说明,感觉容易引起误导(我就是),双亲委派模型->重写loadClass()方法,自定义类加载器->重写findClass()方法应该需要被强调一下。

@Snailclimb
Copy link
Owner

不想用双亲委派模型肯定不是覆盖findClass方法呀,覆盖这个方法就等于默认使用双亲委派模型。 在 2020-07-28 16:41:48,"Zerah" notifications@github.com 写道: 如果我们不想用双亲委派模型怎么办? 不想使用双亲委派模型,我们可以自定义自己的类加载器,需要继承 java.lang.ClassLoader,但是如果是要自定类加载器,也是需要继承ClassLoader,但是覆盖的是findClass方法,这点需要做下补充说明,这点看源码就可以确认,可以参考博客:https://blog.csdn.net/SEU_Calvin/article/details/52315125,因为最近面试经常被问到,之前被误导了,面试官反复确认,我还是说是重写loadClass方法,因而这点感觉需要做下补充说明。 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

没问题的,就是可能之前我没表述清楚,我想表达的是:之前楼主没有对这个情况做区分说明,感觉容易引起误导(我就是),双亲委派模型->重写loadClass()方法,自定义类加载器->重写findClass()方法应该需要被强调一下。

看一下这个描述有问题不?
image

@ZerahMu
Copy link
Author

ZerahMu commented Jul 31, 2020 via email

@Snailclimb Snailclimb added enhancement New feature or request or suggestion typo Correct typos labels Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request or suggestion typo Correct typos
Projects
None yet
Development

No branches or pull requests

3 participants