comp.lang.ada
 help / color / mirror / Atom feed
From: "jimmaureenrogers@worldnet.att.net" <jimmaureenrogers@worldnet.att.net>
Subject: Re: Universal type in Ada
Date: 16 Jun 2005 07:19:43 -0700
Date: 2005-06-16T07:19:43-07:00	[thread overview]
Message-ID: <1118931583.875455.75480@o13g2000cwo.googlegroups.com> (raw)
In-Reply-To: 1118928231.090737.170070@g44g2000cwa.googlegroups.com


zw@cs.man.ac.uk wrote:
> Hi, thank you very much. This is a great idea to create pointers to an
> Object. I also have the same idea, but my problem is a pointer must be
> declared with a specific type such as a pointer to an Integer. However,
> in Ada, when we declared Object as an abstract superclass, the existing
> types like Integer, Float, String are not an Object, we could easily
> define a superclass called "Object" and define all of our types
> inherited from the "Object", this way we will get roughly same
> functionalities like Object as the root type. However, there is no way
> to cope with existing types like Integer. I would like to know that
> whether this is possible to define a root type like "Object" in Java so
> that whatever a "Method" is, it will always return an "Object"? because
> all classes are inherited from "Object", so an Integer is an Object, a
> Float is an Object, ...........

Java does not solve this problem any better than Ada.
The Java primitive types do not inherit from Object. Java provides
wrapper classes for primitive types, but they cannot be used
interchageably with the primitive types themselves, there is always
a type conversion required.

Ada allows you to create a tagged type, either concrete or abstract,
as the root of an inheritance hierarchy. You can then deal with
types such as T'Class and "access T'Class".

Java requires reflection because it provides the Object class. One
result of using a universal ancestor class is the confusion of having
a reference possibly point to either a Float (the wrapper class for the
float primitive type) or a Button (representing a GUI component). You
must then have reflection capabilities so that you can determine what
kind of Object you are pointing to. The methods inherited from Object
are useful in a general sense, but not much help when trying to deal
with characteristics of different classes that do not have anything
in common except the Object class.

Many Java designs include sloppy inheritance hierarchies encouraged by
the availability of the Object references. If you are converting a
program from Java to Ada you should try to do more than simply
recreate a Java inheritance hierarchy using Ada syntax. You should
re-design the program to use Ada as Ada.

Consider converting an Ada program to Java. What if the Ada program
used tasks with entries and the select clause in at least one of the
tasks included a terminate option? How would you express that in Java
syntax? Java has no direct equivalent to the Ada select clause. Java
has no direct equivalent to the terminate option. Even more
difficult, what if one task called the entry in another task using a
selective entry call? Java provides no direct equivalent for a
selective entry call.  You would need to re-design the Ada program
so that you could get equivalent functionality using Java syntax.
You might not be able to implement some Ada features directly in Java.
You might need to settle for similar, if not fully equivalent
functionality.

Jim Rogers




  reply	other threads:[~2005-06-16 14:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-15 13:07 Universal type in Ada zw
2005-06-15 13:32 ` Larry Kilgallen
2005-06-16 13:13   ` zw
2005-06-16 14:36     ` Preben Randhol
2005-06-17  2:54     ` Stephen Leake
2005-06-19 17:38     ` Martin Krischik
2005-06-15 13:55 ` Dmitry A. Kazakov
2005-06-15 14:37   ` Preben Randhol
2005-06-15 16:48     ` Dmitry A. Kazakov
2005-06-15 14:34 ` Preben Randhol
2005-06-16 13:10   ` zw
2005-06-15 16:31 ` Georg Bauhaus
2005-06-16  8:18 ` Ole-Hjalmar Kristensen
2005-06-16 11:59   ` Dmitry A. Kazakov
2005-06-16 13:23     ` zw
2005-06-16 14:19       ` jimmaureenrogers [this message]
2005-06-16 14:31       ` Dmitry A. Kazakov
2005-06-19 17:31       ` Martin Krischik
2005-06-19 17:26 ` Martin Krischik
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox