Some generic anonymous class overriding methods compile, while others don't

I have the following (stripped-down) code. The abstract class SessionHandler<T> is used by other code to define and run an operation that needs a session to something. This is best done in my code with anonymous classes, because of the shear number of operations defined. In the EntityOps<T> class, these work great. But, in the last class shown here, SomeClass, the anonymous class definition fails, though the semantics are almost identical. (List<T> vs.List<AnotherClass>) What am I doing wrong here? Or is this a bug in Java?
Thanks, Tom
public interface IEntityOps<T> {
    T get();
    List<t> getAll();
public abstract class SessionHandler<T> {
    abstract T handle(Session session) throws Throwable;
    public final T perform() {
        ... calls handle(session) ...
// These anonymous class definitions compile fine!
public class EntityOps<T> implements IEntityOps<T> {
    public T get() {
        T ret = null;
        ret = new SessionHandler<T>() {
            T handle(Session s) throws Throwable {
                T ret = (some T object calculation);
                return ret;
        }.perform();
        return ret;
    public List<T> getAll() {
        T ret = null;
        return new SessionHandler<List<T>>() {
            List<T> handle(Session s) throws Throwable {
                List<T> ret = (some List<T> calculation);
                return ret;
        }.perform();
// This anonymous class definition fails with the error:
// "SomeClass.java": <anonymous someMethod> is not abstract and does not override abstract method handle()
//     in SessionHandler at line XX, column XX
public class SomeClass {
    public List<AnotherClass> someMethod() throws {
        List<AnotherClass> ret = null;
        ret = new SessionHandler<List<AnotherClass>>() {
            List<AnotherClass> handle(Session s) throws Throwable {
                List<AnotherClass> ret = (some List<AnotherClass> calculation);
                return ret;
        }.perform();
        return ret;
}

I added @Override above the abstract method override, and it provides this additional error:
"HousingConfigImpl.java": method does not override a method from its superclass at line 382, column 17
I have also reconstructed the code layout in a separate set of classes that have no dependancies, but there's no error coming from these!
public class CustomThing {
public interface ISomeInterface<T> {
    List<T> interfaceMethod();
public abstract class SomeAbstractClass<T> {
    private Class _c = null;
    public SomeAbstractClass(Class c) {
        _c = c;
    protected Class getC() {
        return _c;
    public abstract T methodToOverride(Object neededObject) throws Throwable;
    public final T finalMethod() {
        try {
            return methodToOverride(new Object());
        } catch(Throwable e) {
            throw new RuntimeException(e);
import java.util.List;
import java.util.Collections;
public class SomeInterfaceImpl<T> implements ISomeInterface<T> {
    public List<T> interfaceMethod() {
        return new SomeAbstractClass<List<T>>(CustomThing.class) {
            public List<T> methodToOverride(Object neededObject) throws Throwable {
                return Collections.emptyList();
        }.finalMethod();
import java.util.Collections;
import java.util.List;
public class SomeOtherClass {
    public List<CustomThing> someMethod() {
        return new SomeAbstractClass<List<CustomThing>>(CustomThing.class) {
            public List<CustomThing> methodToOverride(Object neededObject) throws Throwable {
                return Collections.emptyList();
        }.finalMethod();
}So, there's something about my code that causes it to be, somehow, different enough from the example provided above so that I get the error. The only differences in the override method definitions in my actual code are in the return type, but those are different in the example above as well. Here are the class declarations, anonymous abstract class creation statements, and abstract method declarations from the actual code.
public abstract class SessionHandler<T> {
    abstract T handle(Session session) throws Throwable;
public class EntityOps<T> implements IEntityOps<T> {
            return new SessionHandler<List<T>>(_mgr, _c, "getAll" + _c.getName()) {
                List<T> handle(Session s) throws Throwable {
public class HousingConfigImpl implements IHousingConfigOperations, ISessionFactoryManager {
            ret = new SessionHandler<List<Tenant>>((ISessionFactoryManager)this, Housing.class, "getTenantsInNeighborhood") {
                List<Housing> handle(Session s) throws Throwable {I can't for the life of me see any syntactical difference between my example and the real code. But, one works and the other doesn't.

Similar Messages

  • Name binding in anonymous class vs. method

    Hi,
    The following program prints 0, then 3. Can anyone explain why the inner class in method() uses field 'x', while method1() uses parameter 'x'? Is this case well-defined by the Java spec?
    Thanks,
    Shlomy
    public abstract class A implements Runnable {
         public int x = 0;
         public static void method(final int x) {
              A a = new A() {
                   public void run() {
                        System.err.println(x);          
              a.run();
         public static void method1(final int x) {
              System.err.println(x);
         public static void main(String [] args) {
              method(3);
              method1(3);
    }

    Hello Shlomy,
    John Rose wrote a [blog post|http://blogs.sun.com/jrose/entry/scope_ambiguities_between_outer_and] regarding this topic. Originally (before 1.4) you would have gotten an error, today you can't count on "Mother Compiler" to point out ambiguities for you.
    Quote from the blog post:
    If there is no such qualifier possible, the intended variable is a local, and it may therefore be renamed to remove the ambiguity.With kind regards
    Ben
    Edited by: BenSchulz on Feb 16, 2010 8:28 AM added quote

  • DPS: pinch and zoom function not working on all pages within folio (v30 tools using the pdf setting). What would cause some pages to pinch and zoom fluidly, while other pages appear a bit sticky? Could it be a button on the wrong layer?

    What would cause some pages in the same folio to pinch and zoom fluidly, while other pages appear a bit sticky? Could it be a button on the wrong layer that's not allowing the pinch and zoom to work?
    I do have a "go to state" button that enlarges graphic to full page on the page. Could this be cancelling the pinch and zoom functionality? Would a box with text wrap ON affect the ability to pich and zoom? What else may be causing this?

    What would cause some pages in the same folio to pinch and zoom fluidly, while other pages appear a bit sticky? Could it be a button on the wrong layer that's not allowing the pinch and zoom to work?
    I do have a "go to state" button that enlarges graphic to full page on the page. Could this be cancelling the pinch and zoom functionality? Would a box with text wrap ON affect the ability to pich and zoom? What else may be causing this?

  • Some websites I can save as bookmarks while others will not allow me to save them as bookmarks. I have gone through the scenarios to determine what is causing this to occur to no avail. Can anyone help me?

    Most websites I try to save will NOT save as a bookmark...not sure why? Some sites will work while others will not

    This can be a problem with the file places.sqlite that stores the bookmarks and the history.
    * http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox
    * http://kb.mozillazine.org/Bookmarks_not_saved

  • I have had wireless issues sense Leapord, any fixes yet? its a shame that my wife has to sit in front of our 27 inch imac on a $300 Windows computer to use the web effectively. I have tried all fixes  and some work while others don't but all temporary

    This Lion wireless issue has become more than just an irritation, so much so, my wife has resorted to sitting in front of a 27 inch imac with a 300 dollar Walmart Windows computer to get the bills paid and use the web. And yes, there is not a fix out there I haven't tried over the last year or so, some worked and some didn't, but all were temporary at best. Same issue with my Macair, I wonder if its a hardware issue, like the video card in my 2006 MBP, it went out after the warrenty and then I found out there was a calss action suit going on over it, unfortunately Apple wouldn't cover it and wanted 7oo bucks to fix it, sold that as parts.
    While i really like me Macs, I own three, I may have to bow out and stick with LINUX, that has yet to let me down, anyone know if Mountain will fix this issue? or are we all just waiting for defective WiFi cards to fail at our own expense, PS, got three Macs for sale.

    Sounds like you're getting kernel panics, which are usually, but not always, caused by hardware problems, with memory being one of the regular culprits.
    First thing I would do is to get our your original OS X disks, insert the first one (should say 'AHT version x.x' in small print on the label - if not, find the one that does), and reboot holding the Alt key down. Choose the Apple hardware test, and when prompted, choose the extended test. If you have either of the TechTool programs, they can do similar testing. Does that identify any hardware issues?
    Next, I'd download rember from http://www.kelleycomputing.net/rember/ . This is a memory testing program that you can set to run overnight. Does it come up with any errors? If so, try resetting your memory card(s) by removing and putting back into the computer. Rerun memory test.
    This FAQ will provide other details: http://www.thexlab.com/faqs/kernelpanics.html

  • Some Photoshop layers are offline in Premiere, while others -- from the same .PSD doc, are fine -- how to fix?

    I have a simple animation in Premiere that uses imported Photoshop layers, fading each one on at a time over a moving background. Suddenly, today, after months of no problems, I'm seeing that SOME of the layers are offline, while the rest are linked properly. They are all from the same underlying .PSD file. But I can't seem to relink them. Any tips?

    I have found in CS5.5 that if I imported a psd in layers, and then later changed one of the layers, I had to reimport and replace the files sometimes.  I haven't figured out why.

  • HT201272 Some of my song purches have downloaded while others will not.  Any ideas how to fix this?  I've tried to hit songs still not downloaded and it says there are no songs to be downloaded.  Thanks

    I've bought several songs from the iTunes stores.  Some of the songs automatically download to my laptop, which is set up to receive these songs.  Other songs won't download no matter what I try.  They should be downloading to my Windows Media Player which is the default player.  I'm running Windows 7.  If you can help I'd really appreciate it!

    If the songs are still on your ipod, make sure autosync is disabled in iTunes on your computer, connect and right click on it in the device list, then choose "transfer purchases" to copy all bought media and apps from your ipod to your computer.
    If the songs are not on your computer and got deleted from your ipod as well, you can't get them back, unless you have a backup of your iTunes library as part of your computer backup.

  • Some clients get Default Gateway assigned from WRT300N while others don't

    Two existing desktops, one wired other wireless and existing laptop wireless connects to internet fine.
    Trying to add work laptops, they aquire wireless signal, gets DHCP IP address assigned but doesn't connect. Looked at the ipconfig output and shows no default gateway - router IP is set to 192.168.1.1 - with everything default, I did a reset on it.
    The existing machines all have default gateway assigned. Only difference I see is work machines are XP pro. Never had problems with work laptops connecting anywhere else.
    Any ideas on how to setup so work laptops can connect?
    Solved!
    Go to Solution.

    namralk wrote:
    Ethernet adapter VMware Network Adapter VMnet8:
            Connection-specific DNS Suffix  . :
            Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
            Physical Address. . . . . . . . . : 00-50-56-C0-00-08
            Dhcp Enabled. . . . . . . . . . . : No
             IP Address. . . . . . . . . . . . : 192.168.1.1
            Subnet Mask . . . . . . . . . . . : 255.255.255.0
             Default Gateway . . . . . . . . . : 
    You have configured vmware on your computer to use 192.168.1.1 on the VMnet8 adapter. This means the computer uses 192.168.1.1 itself on that adapter and obviously won't set 192.168.1.1 as default gateway on your wireless adapter because 192.168.1.1 is the computer itself.
    Fix your network configuration in vmware. After that a "ipconfig /renew *" or a reboot should obtain a new working lease including the default gateway. Make sure vmware does not use the 192.168.1.0/255.255.255.0 subnet for it's network adapters.

  • Some movies are not syncing into iTunes , while others are . I checked and they are all .mp4 , and is there any other way to sync movies to my ipad ?

    I have tried to sync movies installed on my windows (Breaking Bad) to my iPad so i can watch the series on it , but when I try to insert the episode to iTunes nothing happens 

    Hey there ckhoury13,
    It sounds like your video files may be incompatible with iTunes. Here is an article that will help you determine if your video files need to be converted before they can be moved into iTunes:
    iTunes: Frequently asked questions about viewing and syncing videos
    http://support.apple.com/kb/HT2729
    What video content works with iTunes and mobile devices?
    iTunes:
    Video content purchased from the iTunes Store.
    QuickTime and MPEG-4 movie files that end in ".mov", ".m4v", or ".mp4" and are playable in QuickTime Player.
    Video podcasts.
    iTunes Digital Copies.
    iTunes Store Movie Rentals (Requires iTunes 9 or later).
    Mobile Devices:
    Video content purchased from the iTunes Store.
    Videos that have been shared to iTunes using QuickTime Player (Mac OS X v10.6 Snow Leopard).
    Videos that have been re-encoded for iPod with QuickTime 7 Pro.
    Videos that have been re-encoded for iPod with iMovie, Final Cut Pro, and others. Refer to Exporting a movie from iMovie HD to iPod for an iMovie HD tutorial.
    Video Podcasts that have been created for mobile devices.
    Video files after using the iTunes File > Create New Version > Create iPod or iPhone version option.
    Video files after using the iTunes File > Create New Version > Create iPad or AppleTV version option (iPad and AppleTV only).
    See below for detailed movie specifications.
    iTunes Store Movie Rentals (Requires iTunes 9 or later).
    Take care, and thanks for visiting the Apple Support Communities.
    Cheers,
    Braden

  • Why do some questions have over 10,000 views but others don't?

    I just want to know why.

    Most of the time (most of the time), this happens because a particular topic is linked to from one or more other websites. This can happen if a technical issue is being discussed elsewhere and the answer (or the best place to complain) is here, but it can also happen when something funny happens here that is picked up elsewhere on the Web. (I remember an iPhone topic about a woman who found explicit pictures on her husband's phone, he lied about it and she came here where she received the brutal truth from members. That topic was all over the internets within a couple of days and the topic soon had 100s of thousands of views.)

  • Problems with extension of generic abstract class

    Hello,
    I'm having some problems with the extension of a generic abstract class. The compiler tells me I have not implemented an abstract method but I think I have. I have defined the following interface/class hierarchy:
    public interface Mutator<T extends Individual<S>, S> {
         public void apply( T<S> ind );
    public abstract class AbstractMutator<T extends Individual<S>, S> implements Mutator<T, S> {
         public abstract void apply( T<S> ind );
    }Now I implement AbstractMutator as such:
    public class BinaryMutator extends AbstractMutator<StringIndividual<Integer>, Integer> {
         public void apply( StringIndividual<Integer> ind ) { ... }
    }The compiler says:
    BinaryMutator.java:3: ga.BinaryMutator is not abstract and does not override abstract method apply(ga.Individual<java.lang.Integer>) in ga.AbstractMutator
    Why does it say the signature of the abstract method is apply(Individual<Integer>) if I have typed the superclass as StringIndividual<Integer>?
    Thanks.

    Yes, but the abstract method takes an arg of type <T extends Individual>. So it takes an Individual or a subclass thereof, depending on how I parameterise the class, right? StringIndividual is a subclass of Individual. So if I specify T to be StringIndividual, doesn't the method then take an arg of type StringIndividual?

  • I am new to Mac and am having trouble with uploading images from my pictures folder to Facebook and other share sites- some of my images are accessible while others are seemingly locked....

    I am new to Mac and am having trouble up loafing images from my pictures folder to photography sites and Facebook. Some of the saved images are accessible, while others are not, ( they are light colored and cannot be uploaded) I am not saving them any differently.

    Hi Robodisko,
    Thanks for your prompt reply...... 
    I often proof my work in preview then edit images in photoshop and rename from there.  The dsc images are renamed to correlate the name of the class etc.  i.e. dcs_001 is saved as the file name required 7A.jpeg etc.
    The file names are required to correlate what is what and so on..........

  • Some of my web pages are distored and others are not...how can I fix this?

    I have been using firefox for months now with no problems but recently I updated and now some of my web pages display fine while others that have viewed many times are now distorted and unusable...can anyone help me out with this problem.but keep in mind it's only on certain web pages that I view everyday...but if I do a search and/or browse other web sites it's fine and I have no problems

    Reset the page zoom on pages that cause problems: <b>View > Zoom > Reset</b> (Ctrl+0 (zero); Cmd+0 on Mac)
    * http://kb.mozillazine.org/Zoom_text_of_web_pages
    * http://kb.mozillazine.org/Websites_look_wrong
    * http://kb.mozillazine.org/Website_colors_are_wrong

  • Extremely low-res pics when copied to photostream while others are fine?

    I have some downloaded iPad (New iPad, iPad 3) wallpaper images that I copied to Photo Stream so I could use them on my new iPhone 5. Some of the images copied just fine, while other pictures are low resolution &amp; very pixelated. I thought maybe I was trying to copy too many at once. So I deleted the bad ones and tried again, copying each pic one at a time. They still show on Photo Stream at very low resolution. Does anybody know why, and what I can do to fix this?

    OK, I guess I figured it out...
    Below is a sample of one of the images I was trying to put on Photostream.
    The problem must be something with iOS, because the garbled image on the left only looks that way on the iPad 3 & iPhone 5. When accessed from my PC, the same image is at full resolution (2048x2048). And then when I upload the same image back to Photostream, it still gets resized to 1536x1563, but at much better quality as can be seen in the image on the right.
    I'm glad I found a workaround, but it's very annoying that it doesn't work the way it is supposed to.

  • ER: Override Methods feature should detect anonymous inner class scope

    Hi,
    Given the following code:
    public class Class1 {
        public static void main(String[] args) {
            Thread t = new Thread() {
                // line 4
            t.start();
    }When the cursor is placed on line 4, activating the Override Method dialog (Source menu), should show Thread methods that I can override, in addition to Object methods. Currently only the method from class Object are being shown. The same treatment should also apply to local method inner classes. This happens with the latest 11g preview 3, and all previous versions.

    Hi,
    I'll file an ER
    Frank

Maybe you are looking for