From 69c7ac5133a283d1a6b25e5d7296627ddbd2c194 Mon Sep 17 00:00:00 2001 From: jjenista Date: Thu, 19 Feb 2009 20:51:16 +0000 Subject: [PATCH] allow printing of objects with toString() --- Robust/src/ClassLibrary/System.java | 13 ++++++++++--- Robust/src/Tests/TertiaryTest.java | 9 +++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Robust/src/ClassLibrary/System.java b/Robust/src/ClassLibrary/System.java index 1b6cf9e9..2fdbc2dd 100644 --- a/Robust/src/ClassLibrary/System.java +++ b/Robust/src/ClassLibrary/System.java @@ -9,14 +9,21 @@ public class System { public static native void printString(String s); public static void println(String s) { - System.printString(s); - System.printString("\n"); + System.printString(s+"\n"); } - + + public static void println(Object o) { + System.printString(""+o+"\n"); + } + public static void print(String s) { System.printString(s); } + public static void print(Object o) { + System.printString(""+o); + } + public static void error() { System.printString("Error (Use Breakpoint on ___System______error method for more information!)\n"); } diff --git a/Robust/src/Tests/TertiaryTest.java b/Robust/src/Tests/TertiaryTest.java index c60ef627..5e370585 100644 --- a/Robust/src/Tests/TertiaryTest.java +++ b/Robust/src/Tests/TertiaryTest.java @@ -1,3 +1,11 @@ +public class Foo { + Foo() {} + public String toString() { + return "aFoo"; + } +} + + public class TertiaryTest { static public void main( String[] args ) { int x = 3; @@ -6,5 +14,6 @@ public class TertiaryTest { System.out.println( "x should be 3: "+x ); System.out.print ( "y should be 6: "+y+"\n" ); System.out.println( "z should be 8: "+z ); + System.out.println( new Foo() ); } } \ No newline at end of file -- 2.34.1