インスタンスのクラスを取得する最良の方法は何ですか?
推奨される方法は何ですか? との違い(パフォーマンス)は何ですか:
- クラスを比較する
if( this.getClass().equals(MyClass.class) ){this.getClass() == MyClass.class これは(またはおそらくを使用して Class.forName("com.test.MyClass"))
と同じようです
のインスタンスをテストします(より読みやすいようです)
if( this instanceof MyClass ){クラスを使用してインスタンスをテストする
if( MyClass.class.isInstance(myInst) ){