[表示 : 全て 最新50 1-99 101- 201- 301- 401- 501- 601- 701- 801- 901- 1001- 2ch.scのread.cgiへ]
Update time : 05/18 20:39 / Filesize : 277 KB / Number-of Response : 1025
[このスレッドの書き込みを削除する]
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧] [類似スレッド一覧]


↑キャッシュ検索、類似スレ動作を修正しました、ご迷惑をお掛けしました

Java入門・初心者質問スレ Part.5



456 名前:デフォルトの名無しさん mailto:sage [2017/11/05(日) 13:12:43.81 ID:z+9Dn5/C.net]
以下のコードをideoneで実行できません。(ブラウザとしてエラーが発生)
どなたか理由を教えてもらえないでしょうか?

import java.lang.reflect.*;
class RefSamp {
public int times = 0;
public RefSamp(int t) {
this.times = t;
}
public void hello(String msg) {
this.hello(msg, this.times);
}
public void hello(String msg, int t) {
System.out.println("Hello, " + msg + " x " + t);
}
}

public class Main {
public static void main(String[] args) throws Exception {
Class clazz = RefSamp.class;
Constructor<?> cons = clazz.getConstructor(int.class);
RefSamp rs = (RefSamp) cons.newInstance(256);
Field f = clazz.getField("times");
f.set(rs, 2);
System.out.println(f.get(rs));
Method m = clazz.getMethod("hello", String.class, int.class);
m.invoke(rs, "refrection!", 128);
boolean pubc = Modifier.isPublic(clazz.getModifiers());
boolean finm = Modifier.isFinal(m.getModifiers());
}
}






[ 続きを読む ] / [ 携帯版 ]

全部読む 前100 次100 最新50 [ このスレをブックマーク! 携帯に送る ] 2chのread.cgiへ
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧]( ´∀`)<277KB

read.cgi ver5.27 [feat.BBS2 +1.6] / e.0.2 (02/09/03) / eucaly.net products.
担当:undef