LoginSignup
1
1

More than 5 years have passed since last update.

Groovyで@SingletonしたクラスからのgetInstance()をJavaからやる

Posted at

はじめ

意外に引っかかりました

@Singleton
class Test{
@I have a=new pen('yeah');
}

こんなクラスがあったとする

Test test=Test.getInstance();//エラー

これではTestクラスのインスタンス持ってこれない。
なぜだ

結論

JavaでGroovyのようにアクセスできるメソッドがあるのでそれを使う。

Test test=(Test)InvokerHelper.getProperty(Test.class,"instance");//OK
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1