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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable 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!news4.google.com!news2.google.com!proxad.net!usenet-fr.net!news.enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Preben Randhol Newsgroups: comp.lang.ada Subject: Re: Universal type in Ada Date: Wed, 15 Jun 2005 16:34:24 +0200 Organization: PVV Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1118846083 29025 212.85.156.195 (15 Jun 2005 14:34:43 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Wed, 15 Jun 2005 14:34:43 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:11376 Date: 2005-06-15T16:34:24+02:00 zw wrote on 15/06/2005 (13:11) : > Hi, I am trying to create a Universal type in Ada such as "Object" in > Java so that I could define a function that returns a value in this > Universal type, then I could lower-cast value in this type to its > specific type such as String, Float or any user-defined types. Because > in Java if a method returns an Object, it could be casted to any other > types that are subtypes of Object. Is there a Universal type in Ada? > Could anyone tell me how to create such types in Ada, please? Why would you want to do something like this? Generally you don't want to use subtypes over types as you loose the advantage of the Ada type checking... Remember that in Ada one can have: function Method (Some_Input : Input_Type) return Integer; function Method (Some_Input : Input_Type) return Float; function Method (Some_Input : Input_Type) return String; And do: Number : Integer := Method (Input); Height : Float := Method (Input); Text : String := Method (Input); then the correct function will be called depending on return type. Please explain what you want to do and we can give better hints to do it in more Ada-wise ways. Preben