3 Replies Latest reply: Aug 23, 2007 9:06 PM by 807605 RSS

    Removing anonymous class from a file filter.

    3004
      I've got a file filter that's creating an anonymous class, which is a bit annoying when I want to compile it all together. How would I condense that into one file? I found a way to make it a named class, but is there a way to keep it all in one file?
      FilenameFilter filter = new FilenameFilter() {
           public boolean accept(File dir, String name) {
                name=name.toLowerCase();
                return ((name.endsWith(".gif")) && (new File(dir+"\\"+name).length() < maxFileSize));
           }
      };
        • 1. Re: Removing anonymous class from a file filter.
          807605
          yea just have your class implement filenamefilter.
          • 2. Re: Removing anonymous class from a file filter.
            3004
            Well like I said, I already know how to make it a named class:
                 static class fileFilter implements FilenameFilter {
                      public boolean accept(File dir, String name) {
            ...
            but it still creates a separate file. I'd like to keep all of my code in one file if possible to make JARs easier, and having one for the sole purpose of this filter seems a bit wasteful to me.
            • 3. Re: Removing anonymous class from a file filter.
              807605
              Well like I said, I already know how to make it a
              named class:
                   static class fileFilter implements FilenameFilter {
                        public boolean accept(File dir, String name) {
              ...
              but it still creates a separate file. I'd like to
              keep all of my code in one file if possible to make
              JARs easier, and having one for the sole purpose of
              this filter seems a bit wasteful to me.
              You appear to be under the influence of some sort of hallucinogenics.

              For example

              1) this is all pointless
              2) you have conflicting "requirements" in some places you talk about not wanting two classes in others two source files.
              3) You didn't do what TuringPest suggested but instead did an abortive hacking attempt at it.

              My advice to you? Sober up. Then come back.