/tutorial/external/Java/example2.e
Specman e | 77 lines | 50 code | 11 blank | 16 comment | 0 complexity | 67e5dc4599fa843d5e0a09b3def18263 MD5 | raw file
1class EXAMPLE2 2 -- Compilation: 3 -- compile_to_jvm example2 4 -- javac ISimple.java 5 -- javac ASimple.java 6 -- Execution: 7 -- java example2 8 -- This example demonstrates how to read and write Java object class and instance 9 -- fields from Eiffel. 10 11creation {ANY} 12 make 13 14feature {ANY} 15 make is 16 local 17 a1: POINTER; b: BOOLEAN; i: INTEGER; d: DOUBLE 18 do 19 -- create new ASimple instance 20 a1 := new_ASimple -- verify that it is an instance of ASimple 21 b := instanceof_ASimple(a1) 22 io.put_string("is a1 an instance of ASimple? " + b.to_string + "%N") 23 -- get the instance variable theInteger 24 i := get_theInteger(checkcast_ASimple(a1)) 25 io.put_string("value of theInteger: " + i.to_string + "%N") 26 -- set the instance variable theInteger to 13 27 set_theInteger(checkcast_ASimple(a1), 13) 28 -- get the instance variable theInteger 29 i := get_theInteger(checkcast_ASimple(a1)) 30 io.put_string("value of theInteger after setting to 13: " + i.to_string + "%N") 31 -- get the class variable theStaticInteger 32 i := get_theStaticInteger 33 io.put_string("value of theStaticInteger: " + i.to_string + "%N") 34 -- set the class variable theStaticInteger to -11 35 set_theStaticInteger(-11) 36 -- get the class variable theStaticInteger 37 i := get_theStaticInteger 38 io.put_string("value of theStaticInteger after setting to -11: " + i.to_string + "%N") 39 -- get the class constant dConstant from ISimple 40 d := get_dConstant 41 io.put_string("value of dConstant: " + d.to_string + "%N") 42 end 43 44feature {ANY} -- externals 45 new_ASimple: POINTER is 46 external "Java class ASimple new ()" 47 end 48 49 checkcast_ASimple (p: POINTER): POINTER is 50 external "Java class ASimple checkcast" 51 end 52 53 instanceof_ASimple (p: POINTER): BOOLEAN is 54 external "Java class ASimple instanceof" 55 end 56 57 get_theStaticInteger: INTEGER is 58 external "Java class ASimple get field static int theStaticInteger" 59 end 60 61 set_theStaticInteger (a: INTEGER) is 62 external "Java class ASimple set field static int theStaticInteger" 63 end 64 65 get_theInteger (p: POINTER): INTEGER is 66 external "Java class ASimple get field int theInteger" 67 end 68 69 set_theInteger (p: POINTER; a: INTEGER) is 70 external "Java class ASimple set field int theInteger" 71 end 72 73 get_dConstant: DOUBLE is 74 external "Java class ISimple get field static double dConstant" 75 end 76 77end -- class EXAMPLE2