Results 1 to 4 of 4

Thread: funtion pointer

  1. #1
    mobintmu is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Post funtion pointer

    Hi everyone
    i'm want write blow code in java . i have about 130 rule function .
    this code has O(n) and i want change it to O(1).
    i think java have Function Pointer but i don't know how dose it work !


    Java Code:
    public Player rule0()
    {
        Deque<Integer> dTail = new ArrayDeque<Integer>();
        dTail.add(1);
        dTail.add(2);
        Player result = new Player(0, 2, dTail);
    
        return result ;
    }
    public Player rule1()
    {
        Deque<Integer> dTail = new ArrayDeque<Integer>();
        dTail.add(61);
        dTail.add(27);
        Player result = new Player(1, 120, dTail);
    
        return result ;
    }
    public Player getRule(int dIndex)
    {
        if (dIndex == 0)
            return rule0();
        if(dIndex == 1)
            return rule1();
    
        Player empty= new Player ();
        return empty ; 
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: funtion pointer

    True "function" pointers I think are proposed to be part of Java 1.8, but are not part of Java 1.7.

  3. #3
    mobintmu is offline Member
    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Default Re: funtion pointer

    what dose it mean ?
    java JDK 1.8?
    i don't know how programming with java

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: funtion pointer

    What you can do instead is create an interface and code your rules as an array of instances of this interface. If all your rules are void methods as in the example the interface could have a single execute() method to do the work.

    (If that doesn't make sense, it time to consult a textbook! Or stick with what you have: but bear in mind that what wroks for a couple of rules might get very clumsy for 130 of them. It's not so much the O(whatever) business, it's the lack of structure and order that the object oriented design attempts to address.)

Similar Threads

  1. this pointer
    By janani@tcs in forum New To Java
    Replies: 10
    Last Post: 08-22-2012, 10:40 AM
  2. how to resolve last funtion
    By spinter in forum Advanced Java
    Replies: 2
    Last Post: 10-28-2011, 02:35 AM
  3. funtion of close() method?
    By hacikho in forum New To Java
    Replies: 7
    Last Post: 10-11-2010, 02:08 AM
  4. A variable pointer
    By tapies in forum New To Java
    Replies: 13
    Last Post: 09-12-2008, 11:44 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •