Created
February 10, 2017 08:44
-
-
Save camark/911bf57f3226e9d1cb010567ca08624c to your computer and use it in GitHub Desktop.
Add 0 to number output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.gm; | |
| import java.io.PrintStream; | |
| import java.lang.reflect.Field; | |
| public class Ttx { | |
| public static void main(String[] args) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { | |
| // TODO Auto-generated method stub | |
| int a=20; | |
| int b=10; | |
| //me(a,b); | |
| me1(a,b); | |
| System.out.println("a="+a); | |
| System.out.println("b="+b); | |
| } | |
| private static void me1(int a, int b) { | |
| // TODO Auto-generated method stub | |
| System.setOut(new PrintStream(System.out){ | |
| @Override | |
| public void println(String s){ | |
| super.println(s+"0"); | |
| } | |
| }); | |
| } | |
| private static void me(Integer a, Integer b) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { | |
| // TODO Auto-generated method stub | |
| Integer aa=a; | |
| Integer bb=b; | |
| Class<? extends Integer> class1=aa.getClass(); | |
| Field afField=class1.getDeclaredField("value"); | |
| afField.setAccessible(true); | |
| afField.setInt(aa, 100); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment