反射机制 --> Class.newInstance() && Constructor.newInstance()
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java
- Domain
- documentation
Research direction
Read the linked JDK 9 Class API and Java Tutorials page on constructor reflection, then locate the relevant reflection documentation in JavaGuide. Update the guidance to address Class.newInstance() deprecation and the stated differences with Constructor.newInstance(), preserving the cited sources.
Written by the indexing model from the issue text.
Description
- JDK9文档中,
Class.newInstance()方法被标识为Deprecated,同时也提到The callclazz.newInstance()can be replaced byclazz.getDeclaredConstructor().newInstance()。 - The Java™ Tutorials中提到Constructor.newInstance()是首选,原因为:
Class.newInstance()can only invoke the zero-argument constructor, whileConstructor.newInstance()may invoke any constructor, regardless of the number of parameters.(Class.newInstance()方法只能调用无参数的构造方法,而Constructor.newInstance()方法可以调用任意参数数量的构造方法。)Class.newInstance()throws any exception thrown by the constructor, regardless of whether it is checked or unchecked.Constructor.newInstance()always wraps the thrown exception with anInvocationTargetException.(Class.newInstance()会抛出任何构造器抛出的受检查异常和不受检查异常;Constructor.newInstance()会将抛出的异常包装在InvocationTargetException中抛出。)Class.newInstance()requires that the constructor be visible;Constructor.newInstance()may invoke private constructors under certain circumstances.(Class.newInstance()要求构造方法可见;而Constructor.newInstance()在某些情况下,可以调用私有的构造方法)
Source1:https://docs.oracle.com/javase/tutorial/reflect/member/ctorInstance.html
Source2:https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html
- Dominant language
- JavaScript
- Stars
- 159k
- Forks
- 46.1k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 10
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Snailclimb/JavaGuide
-
失效链接替换 Open
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Snailclimb/JavaGuide#2922 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 45/100
Snailclimb/JavaGuide#2649 · 2 comments ·
-
perfect content
Difficulty 1/5 Under an hour Newbie friendliness 55/100
Snailclimb/JavaGuide#2453 · 3 comments ·
-
perfect content
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Snailclimb/JavaGuide#2259 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
Snailclimb/JavaGuide#2074 ·
All issues in Snailclimb/JavaGuide
Similar issues
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
georgestephanis/p2026#40 ·
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Margaret-Petersen/food-delivery-app-clone-react-native#1981 ·