当前位置: 首页 > news >正文

wordpress 使用七牛免费网站建设seo

wordpress 使用七牛,免费网站建设seo,发布项目信息的平台,上海猎头公司前十名api中重载函数的原理重载方法是API设计中的一个重要概念#xff0c;尤其是当您的API是流利的API或DSL#xff08; 特定于域的语言 #xff09;时。 对于jOOQ就是这种情况#xff0c;在这种情况下#xff0c;您经常想使用与完全相同的方法名称来与库进行各种交互。 示例尤其是当您的API是流利的API或DSL 特定于域的语言 时。 对于jOOQ就是这种情况在这种情况下您经常想使用与完全相同的方法名称来与库进行各种交互。 示例jOOQ条件 package org.jooq;public interface Condition {// Various overloaded forms of the AND operation:Condition and(Condition other);Condition and(String sql);Condition and(String sql, Object... bindings);// [...]} 所有这些方法都使用“ AND”运算符将两个条件相互关联。 理想情况下实现相互依赖从而造成单点故障。 这会使事情变干 package org.jooq.impl;abstract class AbstractCondition implements Condition {// The single point of failureOverridepublic final Condition and(Condition other) {return new CombinedCondition(Operator.AND, Arrays.asList(this, other));}// Convenience methods delegating to the other oneOverridepublic final Condition and(String sql) {return and(condition(sql));}Overridepublic final Condition and(String sql, Object... bindings) {return and(condition(sql, bindings));}} 泛型和重载的麻烦 当使用Eclipse开发时Java 5世界似乎比实际情况更加光彩照人。 Varargs和泛型在Java 5中作为语法糖引入。它们在JVM中并不是真的存在。 这意味着编译器必须正确链接方法调用在需要时推断类型并在某些情况下创建综合方法。 根据JLS Java语言规范 当在重载方法中使用varargs / generics时存在很多歧义。 让我们详细介绍一下泛型 在jOOQ中要做的一件好事是将常量值与字段一样对待。 在许多地方字段参数像这样重载 // This is a convenience method:public static T FieldT myFunction(FieldT field, T value) {return myFunction(field, val(value));}// Its equivalent to this one.public static T FieldT myFunction(FieldT field, FieldT value) {return MyFunctionT(field, value);} 在大多数情况下上面的方法效果很好。 您可以像这样使用上述API FieldInteger field1 //...FieldString field2 //...FieldInteger result1 myFunction(field1, 1);FieldString result2 myFunction(field2, abc); 但是当T绑定到对象时就会出现麻烦 // While this works...FieldObject field3 //...FieldObject result3 myFunction(field3, new Object());// ... this doesnt!FieldObject field4 //...FieldObject result4 myFunction(field4, field4);FieldObject result4 myFunction(field4, (Field) field4);FieldObject result4 myFunction(field4, (FieldObject) field4); 当T绑定到Object时两种方法突然都适用并且根据JLS它们都不是更具体的 尽管Eclipse编译器通常比较宽容并且在这种情况下直观地链接了第二个方法但是javac编译器不知道该调用要做什么。 而且没有办法解决。 您不能将field4强制转换为Field或Field Object强制链接器链接至第二种方法。 对于API设计人员来说这是个坏消息。 有关此特殊情况的更多详细信息请考虑以下堆栈溢出问题我将此问题报告给Oracle和Eclipse。 让我们看看哪种编译器实现是正确的 http://stackoverflow.com/questions/5361513/reference-is-ambiguous-with-generics 静态导入的麻烦varargs Varargs是Java 5中引入的另一个重要功能。尽管它只是语法糖但在将数组传递给方法时可以节省很多代码 // Method declarations with or without varargspublic static String concat1(int[] values);public static String concat2(int... values);// The above methods are actually the same.String s1 concat1(new int[] { 1, 2, 3 });String s2 concat2(new int[] { 1, 2, 3 });// Only, concat2 can also be called like this, convenientlyString s3 concat2(1, 2, 3); 那是众所周知的。 它与原始类型数组的工作方式与与Object []相同。 它也可以与T []一起使用其中T是泛型类型 // You can now have a generic type in your varargs parameter:public static T T[] array(T... values);// The above can be called type-safely (with auto-boxing):Integer[] ints array(1, 2, 3);String[] strings array(1, 2, 3);// Since Object could also be inferred for T, you can even do this:Object[] applesAndOranges array(1, 2, 3.0); 最后一个例子实际上已经暗示了这个问题。 如果T没有任何上限则类型安全性完全消失。 这是一种错觉因为最后总是可以将varargs参数推断为“ Object…”。 这就是当您重载此类API时这会引起麻烦的方式。 // Overloaded for convenience. Lets ignore the compiler warning// caused when calling the second methodpublic static T FieldT myFunction(T... params);public static T FieldT myFunction(FieldT... params); 起初这看起来是个好主意。 参数列表可以是常量值T…或动态字段Field…。 因此原则上您可以执行以下操作 // The outer function can infer Integer for T from the inner// functions, which can infer Integer for T from T...FieldInteger f1 myFunction(myFunction(1), myFunction(2, 3));// But beware, this will compile too!Field? f2 myFunction(myFunction(1), myFunction(2.0, 3.0)); 内部函数将推断T的Integer和Double。 对于不兼容的返回类型Field Integer和Field Double带有“ Field T…”参数的“打算”方法不再适用。 因此编译器将带有“ T…”的方法一链接为唯一适用的方法。 但是您不会猜测T的可能推断范围。 这些是可能的推断类型 // This one, you can always do:Field? f2 myFunction(myFunction(1), myFunction(2.0, 3.0));// But these ones show what youre actually about to doField? extends Field? f3 // ...Field? extends Field? extends Number f4 // ...Field? extends Field? extends Comparable? f5 // ...Field? extends Field? extends Serializable f6 // ... 编译器可以推断出诸如Field 将NumberComparable 和Serializable扩展为T的有效上限。 但是T没有有效的确切界限。 因此必要的 扩展[上限]。 结论 将varargs参数与泛型结合使用时要特别小心尤其是在重载方法中。 如果用户将通用类型参数正确绑定到您想要的目标则一切正常。 但是如果有一个拼写错误例如将Integer与Double混淆那么您的API用户就注定了。 而且他们不会轻易发现自己的错误因为没有人能读懂这样的编译器错误消息 Test.java:58: incompatible types found : Test.FieldTest.Field? extends java.lang.Numberjava.lang.Comparable? extends java.lang.Numberjava.lang.Comparable? required: Test.Fieldjava.lang.IntegerFieldInteger f2 myFunction(myFunction(1),myFunction(2.0, 3.0)); 参考在JAVASQL和JOOQ博客上我们的JCG合作伙伴 Lukas Eder 谨慎使用了重载API方法 。 相关文章 Java中的数据库架构导航 ORM问题 Java泛型快速教程 使用Spring和Java泛型简化数据访问层 翻译自: https://www.javacodegeeks.com/2011/12/overload-api-methods-with-care.htmlapi中重载函数的原理
http://www.yutouwan.com/news/322213/

相关文章:

  • 有保障的广州网站建设宁波住房和建设局网站首页
  • 影城网站设计湖南长沙解封通知最新
  • 网站建设公司的年报可信网站查询官网
  • 网页设计作业怎么保存贵州百度seo整站优化
  • 网站视频解析做食品怎样选网站
  • 支付网站设计宁德时代网站哪个公司做的
  • 互联网网站开发服务合同范本十大财务软件排名
  • 营销型网站怎么做模板网线
  • 东莞网站制作及推广价格工程建设内容包括哪些
  • wordpress零基础建站软文代写是什么
  • 免费建网站中文域名成都专业手机网站建设推广
  • 网站建设合同续签申请书网站建设类公
  • wordpress网站地图插件wordpress增加导航
  • 广东网站建设网顺企网上海网站建设
  • 电商网站开发合同搜索关键词网站
  • 足球竞猜网站开发云南网站建设一度科技
  • 网站开发框架 简单国外优秀网页设计欣赏
  • 学做网站什么语言合适网站图片标签
  • 做钻石资讯网站天元建设集团有限公司第十一建筑公司
  • 企业网站源码程序多少钱?wordpress弹出框插件
  • 网站构建规划书网络优化主要做什么
  • 代码添加在网站的什么位置大连网站建设信息
  • 软件应用大全做网站优化有什么方法
  • asp网站密码微网站建设对微网站进行策划
  • 网站视频与服务器的关系如何在电脑上重新装wordpress
  • dw怎么做网站地图动画制作软件推荐
  • 网站分栏目怎么做手机网站建设教材
  • 昆山网站建设苦瓜网络Python能开发WordPress
  • 记事本做网站改变图片大小网站排名前十
  • 购物网站哪个便宜收录好的网站有哪些