Results 1 to 4 of 4

Thread: instanceof

  1. #1
    AedonetLIRA is offline Member
    Join Date
    Oct 2010
    Posts
    22
    Rep Power
    0

    Default instanceof

    I'm not even sure if this is possible; I'm inclined to think it's not, or the solution defeats the purpose, but I have an array of 6 ToolViews super classes. At any given point of time I need to get in and place or remove a sub class of ToolView (just for clarity later, the three subclasses are analog, digital and blankspace). When the array in created, I fill it with blank spaces, just to give a neat image in an empty spot, but later when I add an analog or digital view i need to remove the next blank space in line. What I'm doing now doesn't work.

    Java Code:
    ToolView[] tools = new ToolView[6]; 
    
    ... // A for loop that fill the array with blank space
    
    for (int i = 0; i < tools.length; i++) {
        if (tools[i] instanceof BlankSpace) {
            tools[i] = new Analog();
            return;
        }
    }
    If you have any idea what I'm doing wrong please inform me.
    ~Aedon

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    Quote Originally Posted by AedonetLIRA View Post
    What I'm doing now doesn't work.
    Doesn't work how? Does it not detect the BlankSpace objects?

    Just a suggestion: why not fill it with null instead?

  3. #3
    AedonetLIRA is offline Member
    Join Date
    Oct 2010
    Posts
    22
    Rep Power
    0

    Default

    Quote Originally Posted by Zack View Post
    Doesn't work how? Does it not detect the BlankSpace objects?
    It does but it classes it as a ToolView only, it doesn't realize that it was created as a blankspace.

    here's a log of what I discovered:
    Java Code:
    Log.e(TAG, mTools + "" +EmptySpace.class + "\t" +(mTools[i] instanceof EmptySpace) + "");
    and the error

    Java Code:
    11-30 16:45:07.774: ERROR/MainUserWorkArea.WorkBench(3260): [Lappion.userface.GaugeComponents.ToolView;@45f6ae50class MainUserWorkArea.EmptySpace    false

    As for setting it to null, I can no problem. The thing is though, BlankSpace is a graphical representation of blank space (essentially a circle with a line through it).

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    Quote Originally Posted by AedonetLIRA View Post
    As for setting it to null, I can no problem. The thing is though, BlankSpace is a graphical representation of blank space (essentially a circle with a line through it).
    Except that every time you evaluate part of the array, you just check if it's null and convert it to BlankSpace for output.

    As for those errors and such, I'm not sure what you're getting at with them. You never mention what mTools, EmptySpace, WorkBench (etc) are.

Similar Threads

  1. Class, SubClass type (InstanceOf) Question
    By indyjoel in forum New To Java
    Replies: 6
    Last Post: 11-07-2010, 03:55 AM
  2. Use of keyword instanceof
    By darek9576 in forum New To Java
    Replies: 3
    Last Post: 03-14-2010, 10:35 PM
  3. super instanceof Class?
    By mikeiz404 in forum New To Java
    Replies: 11
    Last Post: 01-23-2009, 07:23 PM
  4. using instanceof to get Object type and parent type?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-06-2008, 06:24 PM

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
  •