Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34260 > unrolled thread

enum syntax

Started byruben safir <ruben@mrbrklyn.com>
First post2016-05-07 23:58 -0400
Last post2016-05-20 18:01 -0700
Articles 5 — 5 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  enum syntax ruben safir <ruben@mrbrklyn.com> - 2016-05-07 23:58 -0400
    Re: enum syntax Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2016-05-07 21:43 -0700
      Re: enum syntax Roedy Green <inquiry@mindprod.com> - 2016-07-12 04:35 -0700
    Re: enum syntax Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-08 07:22 -0400
    Re: enum syntax Roedy Green <see_website@mindprod.com.invalid> - 2016-05-20 18:01 -0700

#34260 — enum syntax

Fromruben safir <ruben@mrbrklyn.com>
Date2016-05-07 23:58 -0400
Subjectenum syntax
Message-ID<ngmdhi$ics$1@reader1.panix.com>
How is there no closing paran and a method included as an enum entry?

what is this syntax ?


/**
 * An enumeration representing all base types in Calc. It also includes
 * the ERROR designation, used by the type checker to propagate errors.
 */
public enum Type {
    INT,
    FLOAT,
    BOOL,
    STRING,
    ERROR;

    /**
     * The types form a hierarchy, with ERROR at the root.
     * @return The least upper bound of this and that.
     */
    public Type leastUpperBound(Type that) {
        if(this == that)
            return this;
        if((this == INT && that == FLOAT)
            ||(this == FLOAT && that == INT))
            return FLOAT;
        return ERROR;
    }

    /**
     * Determines whether the type is numeric, defined as INT or FLOAT.
     */
    public boolean isNumeric() {
        return leastUpperBound(FLOAT) == FLOAT;
    }
}
-- 
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com

DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com

Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013

[toc] | [next] | [standalone]


#34261

FromKnute Johnson <nospam@rabbitbrush.frazmtn.com>
Date2016-05-07 21:43 -0700
Message-ID<ngmfvn$1da$1@dont-email.me>
In reply to#34260
On 5/7/2016 20:58, ruben safir wrote:
> How is there no closing paran and a method included as an enum entry?
>
> what is this syntax ?
>
>
> /**
>  * An enumeration representing all base types in Calc. It also includes
>  * the ERROR designation, used by the type checker to propagate errors.
>  */
> public enum Type {
>     INT,
>     FLOAT,
>     BOOL,
>     STRING,
>     ERROR;
>
>     /**
>      * The types form a hierarchy, with ERROR at the root.
>      * @return The least upper bound of this and that.
>      */
>     public Type leastUpperBound(Type that) {
>         if(this == that)
>             return this;
>         if((this == INT && that == FLOAT)
>             ||(this == FLOAT && that == INT))
>             return FLOAT;
>         return ERROR;
>     }
>
>     /**
>      * Determines whether the type is numeric, defined as INT or FLOAT.
>      */
>     public boolean isNumeric() {
>         return leastUpperBound(FLOAT) == FLOAT;
>     }
> }
>

 From the JLS "In  addition  to  enum  constants,  the  body  of  an 
enum  declaration  may  contain
constructor and member declarations as well as instance and static 
initializers."  See JLS 8.9.2.


-- 

Knute Johnson

[toc] | [prev] | [next] | [standalone]


#34868

FromRoedy Green <inquiry@mindprod.com>
Date2016-07-12 04:35 -0700
Message-ID<h6l9obtf06d2tp8kf4c6u13a2bevmlsfgh@4ax.com>
In reply to#34261
On Sat, 7 May 2016 21:43:54 -0700, Knute Johnson
<nospam@rabbitbrush.frazmtn.com> wrote:

>> How is there no closing paran and a method included as an enum entry?

I don't see a method attached to an enun constant, though it is a
techquique I use all the time.

for instance in an enum of bookstores, I have a method  to compose a
probe to that store.  It overrides an abstract method common to all
enums.  If I say bookstore.probe() is selects the correct version.

I don't see any () or {} unbalanced.  I am notoriously bad at
proofreading them. Where are they?

[toc] | [prev] | [next] | [standalone]


#34263

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2016-05-08 07:22 -0400
Message-ID<ngn7bf$7qc$1@dont-email.me>
In reply to#34260
On 5/7/2016 11:58 PM, ruben safir wrote:
> How is there no closing paran and a method included as an enum entry?
>
> what is this syntax ?

     There's a good explanation at

http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

Read it, then post again if you still have questions.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

[toc] | [prev] | [next] | [standalone]


#34360

FromRoedy Green <see_website@mindprod.com.invalid>
Date2016-05-20 18:01 -0700
Message-ID<grcvjbh0tqvrj47irtfptguohdsgk1ihcn@4ax.com>
In reply to#34260
On Sat, 7 May 2016 23:58:42 -0400, ruben safir <ruben@mrbrklyn.com>
wrote, quoted or indirectly quoted someone who said :

>       if(this == that)
>            return this;
>        if((this == INT && that == FLOAT)
>            ||(this == FLOAT && that == INT))
>            return FLOAT;

this is does more tersely with a SWITCH.
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Incorrect documentation is often worse than no documentation.
~ Bertrand Meyer (born:1950 age 65)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web