Search:

Type: Posts; User: Baldyr

Page 1 of 2 1 2

Search: Search took 0.32 seconds.

  1. Replies
    9
    Views
    51

    Re: Creating generic version of methods

    Sure

    abstract class Enums{

    public enum TimeOWeek{
    MONDAY ("måndag"),
    TUESDAY ("tisdag"),
    WEDNESDAY ("onsdag"),
    THURSDAY ("tordag"),
    FRIDAY ("fredag"),
  2. Replies
    9
    Views
    51

    Re: Creating generic version of methods

    I'm afraid I'm a bit lost. This is what I got now:

    abstract class Enums {

    static private <E> Class getEnum(Class<E> enumType, String name) {
    for ( enumType t : enumType.values( ) ) {...
  3. Replies
    9
    Views
    51

    Re: Creating generic version of methods

    Sorry, but I'm not seeing any error in the code. I copy-pasted the getLandmass() method and used the same for() loop and only renamed the values. Since it works fine for the original method I'm...
  4. Replies
    9
    Views
    51

    Re: Creating generic version of methods

    Yeah? Did this correct the error?

    private T getEnum(T type, String name) {
    for ( T t : type.values( ) ) {
    if(t.title.equals(name)){
    return t;
    }
    }
    return null;
    }
  5. Replies
    9
    Views
    51

    Creating generic version of methods

    So I have this class containing all my Enum types, also including methods for fetching Enum types based on their title attribute:

    abstract class Enums {

    static private Landmass...
  6. Re: What to code? Interested in learning Java, a member introduction of sorts.

    Almost one week into actually coding Java I'm steamrolling my project on my spare time, learning valuable lessons as I go. What I got thus far are classes for storing global values (abstract),...
  7. Replies
    6
    Views
    40

    [SOLVED] Re: Stupid question on the use of < >

    I guess part of my question was how to read something like that. Is this explained somewhere?
  8. Replies
    6
    Views
    40

    [SOLVED] Re: Stupid question on the use of < >

    define generic type parameters
    This is probably what I was wondering about. Off to practice my Google-fu, then:
    Generic Types (The Java™ Tutorials > Learning the Java Language > Generics (Updated))...
  9. Replies
    6
    Views
    40

    [SOLVED] Stupid question on the use of < >

    I've been noticing these > and < markers in some code and in the Java API, but not been able to find any documentation on what exactly they are used for and how they work. If I only knew what they...
  10. Re: how to ensure that my method wont return the same random number twice in a row

    I'm throwing my two pence in. Would this work?

    int previousRand = 0;
    int newRand = 0;
    Random rand = new Random();

    int getAnotherRand(int range){
    if(range == 0) {
    return 0;
    }
  11. Replies
    16
    Views
    110

    [SOLVED] Re: Compile error for enhanded for loop

    By the way, I finally got the singleton solution working. Thanks Cornix!

    //singleton class for holding global variables
    class Globals {

    // setup singleton instance
    private static Globals...
  12. Re: how to ensure that my method wont return the same random number twice in a row

    This was my initial idea, also, but it fails because the returned value might now be out of range. A fix would only get messy, because there could be a very narrow range and whatnot.
  13. Replies
    16
    Views
    110

    [SOLVED] Re: Compile error for enhanded for loop

    Well, I really can't see the difference between your singleton class and mine. :-? Except that mine is defining variables inside the constructor, whereas yours only assigns the values once the...
  14. Replies
    16
    Views
    110

    [SOLVED] Re: Compile error for enhanded for loop

    That is probably what I've already done as far as the architecture goes, since I've set up a Globals class, a Enums class, a Debug class, a UserInterface class and a Test class. I actually managed...
  15. Replies
    16
    Views
    110

    [SOLVED] Re: Compile error for enhanded for loop

    Yeah, I kinda realize this at some level. This style of coding is probably how I would have implemented this in (a language like) Python. I'll give the singleton route a try, as I've been observing...
  16. Replies
    16
    Views
    110

    [SOLVED] Re: Compile error for enhanded for loop

    For anyone who might be interested to see the end result
    abstract class Globals {

    //private class variables - default values
    private static int[] attributesPrelim = {0, 0, 0, 0};
    private...
  17. Replies
    16
    Views
    110

    [SOLVED] Re: Compile error for enhanded for loop

    I was actually gonna test whether or not totalAttributes would get assigned a default value of zero or not, but thanks for the info. Invaluable advice, all around! ^:)^
  18. Replies
    16
    Views
    110

    [SOLVED] Re: Compile error for enhanded for loop

    Thanks!

    So I should create like a main method which initializes the variables, then?
  19. Replies
    16
    Views
    110

    [SOLVED] Re: Compile error for enhanded for loop

    I'm not entirely sure how to copy text from Command Prompt, but the arrow points to the letter f in for. Like:

    for( int value : attributesFinal ) {
    ^
  20. Replies
    16
    Views
    110

    [SOLVED] Compile error for enhanded for loop

    The second line is resulting in a Illegal start of type error.
    int totalAttributes;
    for( int value : attributesFinal ) {
    totalAttributes =+ value;
    }
    I'm pretty sure that there are no...
  21. Re: What to code? Interested in learning Java, a member introduction of sorts.

    Probably, yes. I believe Python to merely be a "scripting language" of sorts, since it doesn't require any compilation to execute. And on that note, I actually compiled my first ever program today!...
  22. Re: What to code? Interested in learning Java, a member introduction of sorts.

    Yeah, I'm thinking OOP all the way. Actually, I've coded a fair amount object oriented projects in Python so this will be no leap by any means. The difference seems to be that Java more or less...
  23. Re: What to code? Interested in learning Java, a member introduction of sorts.

    I've read through some tutorial online and feel like I could actually start doing this Java thing. I know, the proper way would be to also do all the exercises and start small and all, but I feel...
  24. Thread: basic question

    by Baldyr
    Replies
    17
    Views
    46

    Re: basic question

    For anyone who might care, I pretty much read the tutorials on this site in one sitting and am finally starting to make sense of things. Particularly why Java works the way it does, which was the...
  25. Thread: basic question

    by Baldyr
    Replies
    17
    Views
    46

    Re: basic question

    Oh, now I see. The length of the args tuple is set by the actual number of parameters passed, not by the main method definition. Understanding how these things work makes it easier for me to...
Results 1 to 25 of 34
Page 1 of 2 1 2