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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,25aa3c7e1b59f7b5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-20 13:19:39 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!xmission!newsfeed.telusplanet.net!news1.telusplanet.net.POSTED!not-for-mail Sender: blaak@blight.transcend.org Newsgroups: comp.lang.ada Subject: Re: A case where Ada defaults to unsafe? References: <3C34BF2C.6030500@mail.com> <3C34D252.4070307@mail.com> <3C4A8774.9020808@mail.com> <3C4B16D4.4060200@worldnet.att.net> From: Ray Blaak X-Newsreader: Gnus v5.7/Emacs 20.7 Message-ID: Date: Sun, 20 Jan 2002 21:19:38 GMT NNTP-Posting-Host: 207.194.25.84 X-Trace: news1.telusplanet.net 1011561578 207.194.25.84 (Sun, 20 Jan 2002 14:19:38 MST) NNTP-Posting-Date: Sun, 20 Jan 2002 14:19:38 MST Xref: archiver1.google.com comp.lang.ada:19126 Date: 2002-01-20T21:19:38+00:00 List-Id: Jim Rogers writes: > Both of you are correct, sort of :-). Java does use & and | for > bitwise evaluation. It also uses & and | for boolean evaluation. > This is a case where Java overloads the operator based on the > return type of the operator, something not allowed for people > writing their own Java methods. Actually, it still overloads based on the operands, just like usual Java overloading. Consider: void foo(boolean b) {System.out.println("foo(" + b + ")");} void foo(int i) {System.out.println("foo(" + i + ")");} and then: boolean a = true; boolean b = false; int x = 1; int y = 2; foo(a & b); foo(x & y); the & chosen depends on the operands. The foo is then chosen in turn based on its parameter types, just like normal Java evaluation. E.g. consider also: boolean bar(boolean b) {return b;} int bar(int i) {return i;} and then: foo(bar(a)); foo(bar(x)); Finally, consider this: int i_and = a & b; boolean b_and = x & y; I get the following errors, which indicate that the & is chosen without considering the required result type, for otherwise the errors would be about the invalid operands: Test.java:13: error:Variable "i_and" cannot be initialized by a value of type "boolean" [JLS 4.5.4] Test.java:14: error:Variable "b_and" cannot be initialized by a value of type "int" [JLS 4.5.4] -- Cheers, The Rhythm is around me, The Rhythm has control. Ray Blaak The Rhythm is inside me, blaak@telus.net The Rhythm has my soul.