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,d7b303cc707b3cd4 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Universal type From: Georg Bauhaus In-Reply-To: <1186165731.373877.257550@i13g2000prf.googlegroups.com> References: <1186165731.373877.257550@i13g2000prf.googlegroups.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: # Message-Id: <1186182188.11376.17.camel@sonnenregen> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Date: Sat, 04 Aug 2007 01:03:08 +0200 NNTP-Posting-Date: 04 Aug 2007 01:03:09 CEST NNTP-Posting-Host: 61df3959.newsspool3.arcor-online.net X-Trace: DXC=eGh]9>E_S2H6PJ?[X6JIXEMcF=Q^Z^V3H4Fo<]lROoRA^YC2XCjHcbINA8A]A?:CY@A:ho7QcPOVCQC;]J4lTC=Ic:@6NoheeSO X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:1358 Date: 2007-08-04T01:03:09+02:00 List-Id: On Fri, 2007-08-03 at 11:28 -0700, shaunpatterson@gmail.com wrote: > I'm looking to store different kinds of objects into a vector, queue, > etc > > In Java, everything is derived from Object. Is there something > similar > in Ada? I'd like to be able to store Integers, booleans, etc, as > well > as custom defined objects. While I agree with Dmitry and Maciej (that there must be a reason that Java now has generic containers), if you still wanted containers to hold objects of types derived from Object, you could do just the same thing that Java does, and define an all-emcompassing parent type. In fact, two Ada compilers do exactly this for running Ada programs in a JVM. The "Object" type in the RTL of one of these compilers is type Object is tagged limited null record; type Object_Ptr is access all Object'Class; function hashCode(Obj : access Object) return Integer; -- see java.lang.Object_ops package for rest of -- "Object" abstraction Package Object_ops starts function getClass(Obj : access Object'Class) return Class_Ptr; function toString(Obj : access Object'Class) return String_Ptr; function "="(Left: Object'Class; Right : Object'Class) return Boolean; procedure notify(Obj : access Object'Class); ... Since Java objects stored in containers are really references to heap allocated objects, you would be doing the same using access values in Ada.