首页 \ 问答 \ 覆盖泛型方法(Override generic method)

覆盖泛型方法(Override generic method)

在JLS(Java语言规范)中:子签名的概念被设计用来表示两个方法之间的关系,这两个方法的签名不相同,但其中一个可能会覆盖另一个。 具体来说,它允许一种方法,其签名不使用泛型类型来覆盖该方法的任何泛化版本。

interface CollectionConverter<U> {
    <T> List<T> toList(Collection<T> c);

    void fooMethod(Class<?> c);

    <E>Comparable<E> method3(E e);

    Comparable<U> method4(U u);
}

class Overrider implements CollectionConverter<Integer> {
    @Override
    public List toList(Collection c) {
        return null;
    }

    @Override
    public void fooMethod(Class c) {

    }

    @Override
    public  Comparable method3(Object o) {
        return null;
    }

    @Override
    // compile error, have to change Object to Integer 
    public Comparable method4(Object u) {                       

        return null;
    }
}

根据JLS,我明白为什么前3种方法能够正常工作,但我无法弄清楚为什么method4有一个编译错误,它说类型Overrider的方法method4(Object)必须覆盖或实现一个超类型方法。


According to the JLS (Java Language Specification):

The notion of subsignature is designed to express a relationship between two methods whose signatures are not identical, but in which one may override the other. Specifically, it allows a method whose signature does not use generic types to override any generified version of that method.

This code is based on the JLS example:

interface CollectionConverter<U> {
    <T> List<T> toList(Collection<T> c);

    void fooMethod(Class<?> c);

    <E>Comparable<E> method3(E e);

    Comparable<U> method4(U u);
}

class Overrider implements CollectionConverter<Integer> {
    @Override
    public List toList(Collection c) {
        return null;
    }

    @Override
    public void fooMethod(Class c) {

    }

    @Override
    public  Comparable method3(Object o) {
        return null;
    }

    @Override
    // compile error, have to change Object to Integer 
    public Comparable method4(Object u) {                       

        return null;
    }
}

According to the JLS, I understand why the first three methods work well, but I can't figure out why method4 has this compilation error:

The method method4(Object) of type Overrider must override or implement a supertype method.


原文:https://stackoverflow.com/questions/9731574
更新时间:2023-11-23 17:11

最满意答案

它工作正常。 我点击了它,它出现在用户个人资料页面上: http//cl.ly/image/2Q2k3z3W3E0l

我提出了一个状态并分享了它。 它还在Facebook上展示: http//cl.ly/image/3c1R412x021d

我没有看到任何问题。


It's working fine. I clicked like and it showed up on the users profile page: http://cl.ly/image/2Q2k3z3W3E0l

I put in a status and shared it. It also shows on Facebook: http://cl.ly/image/3c1R412x021d

I'm not seeing any issues.

相关问答

更多
  • 您所指的功能已于2012年11月删除 - https://developers.facebook.com/docs/reference/plugins/like/migration/ The feature you're referring to was removed in November 2012 - https://developers.facebook.com/docs/reference/plugins/like/migration/
  • 如果你想特别使用Facebook你应该使用FacebookSDK for Android。 但据我所知,这可能会给您带来很多问题,相反,我会建议您制作一个Share Intent并让用户选择拆分他们的分数: Intent shareIntent=new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT,"Your score and ...
  • 你使用Dialog就是它显示Dialog的原因。 请改用FB.api 。 ( 注意:您只能在当前用户的墙上发布,而不是发布给他/她的朋友 - 现在已经被Facebook禁用了。) 要在用户的墙上发布,您可以简单地使用 - FB.api('/me/feed', 'post', { link: 'http://mywebsite.com', picture: 'my image', ETC..}, function(response) { if (!response || response.error) ...
  • Facebook本身并不托管这些应用程序。 它只是使用和iframe使它们出现在Facebook页面选项卡中。 应用程序本身由外部服务器托管,外部服务器也必须是您的情况。 因此,如果您计划在某处保存自定义表单数据,那么理想的解决方案是将它们保存到托管应用程序的同一服务器上。 简而言之:是的,您需要制作自己的程序来捕获发布事件。 Facebook itself does not host the applications. It just uses and iframe to make them appear ...
  • Windows.System.Launcher.LaunchUriAsync(new Uri("fb:")); 应该安装应用程序的技巧( http://www.windowsphone.com/s?appid=82a23635-5bd9-df11-a844-00237de2db9e ) 您可以在http://developer.nokia.com/Community/Wiki/URI_Association_Schemes_List中找到更多信息。 请记住,启动自定义uri方案仅适用于Windows Ph ...
  • 您可以将View Controller的引用传递给SKScene,也可以使用NSNotificationCenter 。 我更喜欢使用后者。 首先确保已将Social.framework添加到项目中。 将社交框架导入View Controller #import 然后在View Controller的viewDidLoad方法中添加以下代码: [[NSNotificationCenter defaultCenter] addObserver:self ...
  • [url]参数格式错误。 尝试添加http:// The [url] parameter is malformed. Try adding http://
  • Craigslist不允许嵌入Facebook类按钮所需的脚本/ iframe。 您也无法将脚本/ iframe嵌入到html电子邮件中,因此您只能提供链接。 但是,你可以创建一个像这样的Facebook揭示标签,这需要粉丝在看到内容之前喜欢你的页面。 Facebook文档可以向您显示如何或搜索谷歌。 Craigslist doesnt allow embedding scripts/iframes which would be required for the Facebook like button. ...
  • 您需要使用Facebook和Twitter REST API,而不是使用本机iOS的社交框架对话框。 您不希望显示本机对话框,因为您将无法同时发布。 相反,您需要创建自己的对话框,使用SLRequest将请求发送到网络。 You'll need to use Facebook and Twitter REST API rather than using the native iOS's social frameworks dialogs. You don't want to display the nati ...
  • 它工作正常。 我点击了它,它出现在用户个人资料页面上: http : //cl.ly/image/2Q2k3z3W3E0l 我提出了一个状态并分享了它。 它还在Facebook上展示: http : //cl.ly/image/3c1R412x021d 我没有看到任何问题。 It's working fine. I clicked like and it showed up on the users profile page: http://cl.ly/image/2Q2k3z3W3E0l I put in ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。