From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,63fa88e2f1a3ebea X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!o13g2000cwo.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada Subject: Re: Universal type in Ada Date: 16 Jun 2005 07:19:43 -0700 Organization: http://groups.google.com Message-ID: <1118931583.875455.75480@o13g2000cwo.googlegroups.com> References: <1118928231.090737.170070@g44g2000cwa.googlegroups.com> NNTP-Posting-Host: 209.194.156.4 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1118931590 8839 127.0.0.1 (16 Jun 2005 14:19:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 16 Jun 2005 14:19:50 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: o13g2000cwo.googlegroups.com; posting-host=209.194.156.4; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news1.google.com comp.lang.ada:11420 Date: 2005-06-16T07:19:43-07:00 List-Id: 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