Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
コマンドライン引数としてクラス名を渡す。
$program-name class-name
Scala でこのクラスからオブジェクトをインスタンス化するにはどうすればよいですか? つまり、クラス名からオブジェクトを取得することは可能ですか?
はい、可能です。例えば:
Class.forName("java.lang.String").newInstance
scala ではすべての Java メソッドを呼び出すことができるので、Class.forName(classname).
Class.forName(classname)