Thread: Imbued Godcape Exchange

Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16
  1. #11  
    Registered Member

    Join Date
    Oct 2017
    Posts
    649
    Thanks given
    6
    Thanks received
    119
    Rep Power
    161
    thanks for share
    Reply With Quote  
     

  2. #12  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by Stuart View Post
    values() will create a new copy of the array every time you call it.
    Where can I find documentation to support this?
    Reply With Quote  
     

  3. #13  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Quote Originally Posted by Jason View Post
    Where can I find documentation to support this?
    Its not in the java docs, but it does do this so you cannot tamper with the values of the enum

    Code:
    public enum ExampleEnum {
    
        HELLO,
        WORLD
    
    }
    Code:
    javac -d out -XD-printflat ExampleEnum.java
    Code:
    public enum ExampleEnum extends Enum<ExampleEnum> {
        /*public static final*/ HELLO /*enum*/ ("HELLO",0),
        /*public static final*/ WORLD /*enum*/ ("WORLD",1);
        /*synthetic*/ private static final ExampleEnum[] $VALUES = new ExampleEnum[]{ExampleEnum.HELLO, ExampleEnum.WORLD};
        
        public static ExampleEnum[] values() {
            return (ExampleEnum[])$VALUES.clone();
        }
        
        public static ExampleEnum valueOf(String name) {
            return (ExampleEnum)Enum.valueOf(ExampleEnum.class, name);
        }
        
        private ExampleEnum(/*synthetic*/ String $enum$name, /*synthetic*/ int $enum$ordinal) {
            super($enum$name, $enum$ordinal);
        }
    }

    Reply With Quote  
     

  4. Thankful user:


  5. #14  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by Stuart View Post
    Its not in the java docs, but it does do this so you cannot tamper with the values of the enum

    Code:
    public enum ExampleEnum {
    
        HELLO,
        WORLD
    
    }
    Code:
    javac -d out -XD-printflat ExampleEnum.java
    Code:
    public enum ExampleEnum extends Enum<ExampleEnum> {
        /*public static final*/ HELLO /*enum*/ ("HELLO",0),
        /*public static final*/ WORLD /*enum*/ ("WORLD",1);
        /*synthetic*/ private static final ExampleEnum[] $VALUES = new ExampleEnum[]{ExampleEnum.HELLO, ExampleEnum.WORLD};
        
        public static ExampleEnum[] values() {
            return (ExampleEnum[])$VALUES.clone();
        }
        
        public static ExampleEnum valueOf(String name) {
            return (ExampleEnum)Enum.valueOf(ExampleEnum.class, name);
        }
        
        private ExampleEnum(/*synthetic*/ String $enum$name, /*synthetic*/ int $enum$ordinal) {
            super($enum$name, $enum$ordinal);
        }
    }

    That's really interesting, and very good to know. Thank you.
    Reply With Quote  
     

  6. #15  
    Extreme Donator

    Join Date
    Apr 2015
    Posts
    369
    Thanks given
    215
    Thanks received
    79
    Rep Power
    74
    Quote Originally Posted by Stuart View Post
    values() will create a new copy of the array every time you call it. I think it'd be fine for the usage OP is using and would have very little if any impact on performance.

    I personally don't like the nested if statements or the ternary statements everywhere, not sure why this snippet was released to be honest, I was expecting to see the real magic arena 2 exchanging
    Personally, I learned more about coding from reading other people's work then I did doing java practice tutorials. This was just released for new developers.

    And I used ternary to avoid extra lines of code. And they are useful tools new developers should have.
    Reply With Quote  
     

  7. #16  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Quote Originally Posted by durky View Post
    Personally, I learned more about coding from reading other people's work then I did doing java practice tutorials. This was just released for new developers.

    And I used ternary to avoid extra lines of code. And they are useful tools new developers should have.
    Use ternary statements when it doesn't effect readability of the code
    Reply With Quote  
     

Page 2 of 2 FirstFirst 12

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Skill Cape exchanger (Silab client)
    By MuZzA in forum Tutorials
    Replies: 7
    Last Post: 07-04-2008, 10:20 AM
  2. Universal User Exchange - New!
    By DJ Dan in forum RS2 Server
    Replies: 39
    Last Post: 06-26-2008, 10:27 PM
  3. Sigex - Castle wars Ticket Exchange 100%
    By littleplop in forum Tutorials
    Replies: 60
    Last Post: 02-22-2008, 12:49 PM
  4. 1 Item Exchange Command :d
    By Aggi in forum Tutorials
    Replies: 23
    Last Post: 02-09-2008, 08:43 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •