怎样在同时输出if else 里面的语句

来源:互联网 发布:广联达软件销售电话 编辑:程序博客网 时间:2024/05/16 15:02

使用反射实现

 

package com.xf.parent;

import java.lang.reflect.InvocationTargetException;


/**
 * 輸出helloword
 * @author Administrator
 *
 */
public class Test {
 public static void main(String[] args) {
  try {
   if(System.out.getClass().getDeclaredMethod("print", String.class).invoke(System.out, "hello ")!=null){
    System.out.println("hello ");
   }else{
    System.out.println("word");
   }
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

}