More Related Content
More from sudahiroshi (8)
Enshu4
- 8. コンストラクタ 簡単に言うと,newの処理 PrintWriter writer = new PrintWriter( socket.getOutputStream() ); 例えば,↑が実行されるときの処理. コンストラクタは4種類あるけどどれ? PrintWriter( OutputStream out ) PrintWriter( OutputStream out, booleanautoFlash ) PrintWriter( Writer out ) PrintWriter( Writer out, booleanautoFlash )
- 10. 実行されるコンストラクタをさがそう PrintWriter writer = new PrintWriter( socket.getOutputStream() ); socket.getOutputStram() って何だ? まず,変数宣言を確認する. Socket socket = new Socket(); socketには「new Socket()」が代入されているので,SocketクラスのgetOutputStreamを調べる.
- 12. 該当するコンストラクタ PrintWriter writer = new PrintWriter( socket.getOutputStream() ); よって,該当するコンストラクタは PrintWriter( OutputStream out ) PrintWriter( OutputStream out, booleanautoFlash ) PrintWriter( Writer out ) PrintWriter( Writer out, booleanautoFlash ) であることが分かる. 詳しい説明も読んでおこう.
- 13. 便利なコンストラクタを探す PrintWriter( OutputStream out ) PrintWriter( OutputStream out, booleanautoFlash ) PrintWriter( Writer out ) PrintWriter( Writer out, booleanautoFlash ) ん?このコンストラクタって何だ? Java言語では,同じ働きをするコンストラクタやメソッドが多数定義されている.仕様書によるとautoFlushにtrueを与えると,便利そうである. よって,以下のように書き換えることもできる. PrintWriter writer = new PrintWriter( socket.getOutputStream(), true );