Snailclimb / Snailclimb/JavaGuide

反射机制 --> Class.newInstance() && Constructor.newInstance()

オープン
#1,606 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

enhancement
主要言語
JavaScript
スター
159k
フォーク
46.1k
平均マージ
14時間 36分
マージ済み PR(30日)
6

説明

  1. JDK9文档中,Class.newInstance()方法被标识为Deprecated,同时也提到The call clazz.newInstance() can be replaced by clazz.getDeclaredConstructor().newInstance()
  2. The Java™ Tutorials中提到Constructor.newInstance()是首选,原因为:
  • Class.newInstance() can only invoke the zero-argument constructor, while Constructor.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 an InvocationTargetException.(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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

コンストラクタのリフレクションに関する、リンク先のJDK 9 Class APIおよびJava Tutorialsのページを読み、その後JavaGuideで関連するリフレクションのドキュメントを見つけてください。Class.newInstance()の非推奨化と、Constructor.newInstance()との明記された違いを扱うようにガイダンスを更新し、引用されているソースを保持してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
documentation
issue の種類
ドキュメント
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。