inline classes

Discussion in 'Java' started by Mize-ze, Nov 16, 2006.

  1. Mize-ze

    Mize-ze Guest

    Hi,
    I remember that I saw a code somewhere that sends an inline class as an
    argument but for some reason I cant find any examples now when I
    search for it on the web.

    It looked something like that:

    String files[] = xmlpath.list(
    new class myFilter implements java.io.FilenameFilter
    {
    //Overriden method
    public boolean accept(File dir,String name)
    {
    if
    (dir.getAbsolutePath().equals(xmlRuleProvider.XMLPATH.toString())&&
    name.endsWith(".xml") )
    return true;
    else
    return false;
    }

    } //end of class decleration and (hopefully) instansiating
    );


    But the above code does not compile,
    can someone refer me to a good example?

    Thanks.
    Mize-ze, Nov 16, 2006
    #1
    1. Advertising

  2. Mize-ze

    Ye Dafeng Guest

    Mize-ze wrote:
    > Hi,
    > I remember that I saw a code somewhere that sends an inline class as an
    > argument but for some reason I cant find any examples now when I
    > search for it on the web.
    >
    > It looked something like that:
    >
    > String files[] = xmlpath.list(
    > new class myFilter implements java.io.FilenameFilter

    ~~~~
    I think the "class" is redunant

    > {
    > //Overriden method
    > public boolean accept(File dir,String name)
    > {
    > if
    > (dir.getAbsolutePath().equals(xmlRuleProvider.XMLPATH.toString())&&
    > name.endsWith(".xml") )
    > return true;
    > else
    > return false;
    > }
    >
    > } //end of class decleration and (hopefully) instansiating
    > );
    >
    >
    > But the above code does not compile,
    > can someone refer me to a good example?
    >
    > Thanks.
    >
    Ye Dafeng, Nov 16, 2006
    #2
    1. Advertising

  3. On 16.11.2006 14:08, Mize-ze wrote:
    > Hi,
    > I remember that I saw a code somewhere that sends an inline class as an
    > argument but for some reason I cant find any examples now when I
    > search for it on the web.
    >
    > It looked something like that:
    >
    > String files[] = xmlpath.list(
    > new class myFilter implements java.io.FilenameFilter
    > {
    > //Overriden method
    > public boolean accept(File dir,String name)
    > {
    > if
    > (dir.getAbsolutePath().equals(xmlRuleProvider.XMLPATH.toString())&&
    > name.endsWith(".xml") )
    > return true;
    > else
    > return false;
    > }
    >
    > } //end of class decleration and (hopefully) instansiating
    > );
    >
    >
    > But the above code does not compile,
    > can someone refer me to a good example?
    >
    > Thanks.
    >


    Thread t = new Thread( new Runnable() {
    public void run() {
    System.out.println("hello world");
    }
    } );

    robert
    Robert Klemme, Nov 16, 2006
    #3
  4. Mize-ze

    Oliver Wong Guest

    Oliver Wong, Nov 16, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Abhi
    Replies:
    2
    Views:
    734
    E. Robert Tisdale
    Jul 3, 2003
  2. Alvin
    Replies:
    7
    Views:
    474
    E. Robert Tisdale
    May 6, 2005
  3. Replies:
    3
    Views:
    457
  4. Daniel Vallstrom
    Replies:
    2
    Views:
    1,876
    Kevin Bracey
    Nov 21, 2003
  5. Nish
    Replies:
    4
    Views:
    487
    Thomas Stegen
    Oct 8, 2004
Loading...

Share This Page