M
meridian
In Java can you mix types in collections or arrays like in Python and
Ruby?
(eg like the Python and Ruby examples here...)
thanks for your help....
Ruby?
(eg like the Python and Ruby examples here...)
# Python
class MyClass:
def __str__(self):
return "I'm an object of MyClass"
myObj = MyClass()
l = [0, 1.1, "2", "three", myObj]
for thing in l:
print thing
# output
#
# 0
# 1.1
# 2
# three
# I'm an object of MyClass -------------------------------------------
# Ruby
class MyClass
def to_s
return "I'm an object of MyClass"
end
end
myObj = MyClass.new
l = [0, 1.1, "2", "three", myObj]
for thing in l
puts thing
end
# output
#
# 0
# 1.1
# 2
# three
# I'm an object of MyClass
thanks for your help....