www.digitalmars.com         C & C++   DMDScript  

D - Object as everything

reply Mattias <Mattias_member pathlink.com> writes:
Hi,

1. In Java an Object can be everything, even an array. Is there any equivalence
in D?

2. Java has a standard representation of the fundamental types as objects
(Integer, Float a.s.o.) I haven't seen that in D...

Without these functions it is a little tricky just to have a function f.ex.
like:

Object getProperty( String key );

..in D that can return anything.


Thank you for responding to our questions.

/ Mattias
Jun 02 2003
parent "C. Sauls" <ibisbasenji yahoo.com> writes:
 1. In Java an Object can be everything, even an array. Is there any
equivalence
 in D?
Answer: Nope.
 2. Java has a standard representation of the fundamental types as objects
 (Integer, Float a.s.o.) I haven't seen that in D...
Answer: No you haven't, and you won't. Java's type-wrappers are primarily there for compile-time method-matching. The primitive types are not actually wrapped within the object model unless you explicity use it.
 Without these functions it is a little tricky just to have a function
f.ex.
 like:

 Object getProperty( String key );

 ..in D that can return anything.
Answer: It can be done. Templates, as one example. And for that matter, returning a single generic type has its possible problems as well, because then you have to add checks (in some cases) to find out which type you've gotten. -- C. Sauls
Jun 02 2003