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

logosc网站怎么做的Wordpress的高级版

logosc网站怎么做的,Wordpress的高级版,校园网站开发背景,wordpress卡蜜大家好#xff0c;该是从2012年开始写作的时候了。正如您在其他博客中可能已经看到的那样#xff0c;有一些更改可以使您使用Java编程时的开发人员生活变得更加轻松#xff1a;Diamond运算符#xff0c;Switchs中的Strings#xff0c;尝试使用资源#xff0c;多次捕获等 … 大家好该是从2012年开始写作的时候了。正如您在其他博客中可能已经看到的那样有一些更改可以使您使用Java编程时的开发人员生活变得更加轻松Diamond运算符Switchs中的Strings尝试使用资源多次捕获等 在本文PART I中我们将看到Java 7 Project CoinJSR 334中提出的一些小改动然后在第二部分中我们将对它们进行反编译以查看编译器在做什么对于仅用于教育目的。 你需要什么 NetBeans 7或任何其他支持Java 7的IDE JSDK 7 JAD反编译 [R 或 Java的反编译 钻石算子 泛型帮助我们减少了ClassCastExceptions但是有时它会使代码难以阅读。 钻石算子是一个非常不错的变化。 成像您需要按城市对客户进行分组。 您将需要以下内容 //suppose the classes City and Customer exist ... MapCity,ListCustomer map new HashMapCity,ListCustomer(); ... 现在如果您还需要按国家/地区对数据进行分组怎么办 //suppose the classes Country, City and Customer exist ... MapCountry,MapltCity,ListCustomer map new HashMaplt;Country,MapltCity,ListltCustomer(); ... 现在它开始变得很难阅读对吧 如果您还需要按地区分组怎么办 //suppose the classes Region, Country, City and Customer exist ... MapRegion,MapCountry,MapCity,ListCustomer map new HashMapRegion, MapCountry,MapCity,ListCustomer(); ... 所以你怎么看 读取这样的代码根本不容易。 幸运的是新的Diamond运算符对代码的可读性有很大帮助。 最后的代码可以在Java 7中重新编码如下所示 //suppose the classes Region, Country, City and Customer exist ... MapRegion,MapCountry,MapCity,ListCustomer map new HashMap(); ... 好了很多 开关中的弦 我已经等了很多 我记得我刚开始Java时代的日子我确实需要在switch中使用Strings。 好吧我的等待终于结束了。 在Java的早期版本中您必须编写如下代码 //in a class ... public void stringToNumber(String str) {if(str.equalsIgnoreCase(one)){System.out.println(1);}else if(str.equalsIgnoreCase(two)){System.out.println(2);}else if(str.equalsIgnoreCase(three)){System.out.println(3);} } ... 在Java 7中您可以这样编写 //in a class ... public void stringToNumber(String str) {switch(str){case one:System.out.println(1);break;case two: System.out.println(2);break; case three:System.out.println(3);break;} } ... 甚至NetBeans也可以选择自动转换 尝试使用资源和多重捕获 在此版本中这是一个很好的增强现在您不必担心关闭那些ResultSetStatesFileInputStreams等。 您只需要使用新的try结构编译器就会为您服务。 您甚至可以通过新的try结构将自己的类创建为Closeable这是一个新接口。 以下是通过流进行的经典文件访问 //in a class import java.io.*; ... public static void copyFile(String path) throws IOException, NullPointerException {File file new File(path);FileOutputStream fout null;FileInputStream fin null;try {try {fout new FileOutputStream(file.dat);fin new FileInputStream(file);byte[] bytes new byte[1024];int leido 0;while ((leido fin.read(bytes)) ! -1) {fout.write(bytes, 0, leido);}} finally {if (fout ! null) {fout.close();}if (fin ! null) {fin.close();}}} catch (NullPointerException ex) {ex.printStackTrace();throw ex;}catch (IOException ex) {ex.printStackTrace();throw ex;}} ... 如果您注意到了为了确保打开的流一旦完成就被关闭则必须编写一个try / finally块并自己关闭它们。 在Java 7中可以使用新的try结构和新的NIO.2类以更好的方式和更少的代码行实现相同的行为 //in a class import java.nio.file.*; import java.io.*; ... public static void copyFile(String src) throws IOException, NullPointerException {Path path FileSystems.getDefault().getPath(src);try (FileOutputStream fout new FileOutputStream(file.dat)) {Files.copy(path, fout);} catch (NullPointerException | IOException ex) {ex.printStackTrace();throw ex;} } ... 二进制文字和下划线 现在您可以将整数表示为二进制文字这在编程低级API时非常理想也可以使用下划线以使您的值更易读 //in a class ... public static void coin() {int binaryNum 0b10; //This is number 2 in binary codedouble value1 1000000000; //hard to read?double value2 1_000_000_000; //Easy to read with Java 7double value3 0b101010110111; //hard to read?double value4 0b1010_1011_0111; //Easy to read with Java 7double pi 3.14_15_92; //another example of readability } ... 因此更少的代码更高的生产率和更好的代码可读性是Project Coin的宗旨 在这里没有看到的其他东西。 钻石算子 这是我们在上一篇文章中刚刚看到的钻石操作员示例 //suppose the classes Region, Country, City and Customer exist import java.util.*; ... Mapregion,mapcountry,mapcity,list map new HashMap(); .../region,mapcountry,mapcity,list 现在让我们看看编译器生成的代码是什么样的 import java.util.*; ... java.util.Map map new HashMap(); ... 只是一个老派的地图定义和实例化...为什么 因为这就是泛型的工作方式 When you take an element out of a Collection, you must cast it to the type of element that is stored in the collection. Besides being inconvenient, this is unsafe. The compiler does not check that your cast is the same as the collections type, so the cast can fail at run time.Generics provides a way for you to communicate the type of a collection to the compiler, so that it can be checked. Once the compiler knows the element type of the collection, the compiler can check that you have used the collection consistently and can insert the correct casts on values being taken out of the collection. 这意味着编译器将在编译时检查您是否使用了正确的类并将向生成的类添加任何必需的强制转换。 例如 //suppose the classes Region, Country, City and Customer exist import java.util.*; ... Mapregion,mapcountry,mapcity,list map new HashMap(); Mapcountry,mapcity,list m map.get(new Region()); ... /country,mapcity,list/region,mapcountry,mapcity,list 您将获得如下内容 //suppose the class Region exists import java.util.*; ... Map map new HashMap(); Map m (Map)map.get(new Region()); //the compiler added the cast ... 开关中的弦 记住上一篇文章中介绍的Strings in switch示例 //in a class ... public void stringToNumber(String str) {switch(str){case one:System.out.println(1);break;case two: System.out.println(2);break; case three:System.out.println(3);break;} } ... 反编译之后您会注意到开关状态菜单现在如何支持字符串 //in a class ... public static void stringInSwitch(String str) {String s str;byte byte0 -1;switch(s.hashCode()){case 110182: if(s.equals(one))byte0 0;break;case 115276: if(s.equals(two))byte0 1;break;case 110339486: if(s.equals(three))byte0 2;break;}switch(byte0){case 0: // System.out.println(1);break;case 1: // 01System.out.println(2);break;case 2: // 02System.out.println(3);break;} } ... 是的……这是一个小技巧。 并不是直接在switch语句中支持字符串而是它们的hashCodes是hashCodes是整数。 通过查看代码我意识到最好不要在switch语句中使用Strings因为最后您将获得两个switch语句…… 尝试使用资源和多重捕获 记住上一篇文章中的尝试资源和多捕获示例 //in a class import java.nio.file.*; import java.io.*; ... public static void copyFile(String src) throws IOException, NullPointerException {Path path FileSystems.getDefault().getPath(src);try (FileOutputStream fout new FileOutputStream(file.dat)) {Files.copy(path, fout);} catch (NullPointerException | IOException ex) {ex.printStackTrace();throw ex;} } ... 本示例在一个示例中使用try资源并进行多捕获。 当我尝试使用JAD Java Decompiler对生成的类进行反编译时我对嵌套的try语句有很多误解因此我决定尝试JD Java Decompiler结果如下 //in a class import java.nio.file.*; import java.io.*; ... public static void copyFile(String src) throws IOException, NullPointerException {Path path FileSystems.getDefault().getPath(src, new String[0]);try {FileOutputStream fout new FileOutputStream(file.dat); Throwable localThrowable2 null;try { Files.copy(path, fout);}catch (Throwable localThrowable1){localThrowable2 localThrowable1; throw localThrowable1;} finally {if (fout ! null) { //I added this { symbol for readabilityif (localThrowable2 ! null) { //I added this { symbol for readabilitytry { fout.close(); } catch (Throwable x2) { localThrowable2.addSuppressed(x2); } } //I added this } symbol for readabilityelse { //I added this { symbol for readabilityfout.close(); } //I added this } symbol for readability} //I added this } symbol for readability}} catch (IOException ex) {ex.printStackTrace();throw ex;} } ... 从最后的代码中我们可以看到编译器如何使用新的JDK 7 addSuppressedThrowablevoid类Throwable来确保复制过程中抛出的任何异常不会丢失。 这很重要因为在应用程序中查找错误时您将需要所有可能的异常。 另外请注意所有关闭操作都是在finally语句中完成的以确保在过程结束时始终关闭资源。 二进制文字和下划线 我认为您可以弄清楚对最后一个功能进行反编译后会得到什么…… //in a class ... public static void coin() {int binaryNum 0b10; //This is number 2 in binary codedouble value 1000000000; //hard to read?double value 1_000_000_000; //Easy to read with Java 7double value 0b101010110111; //hard to read?double value 0b1010_1011_0111; //Easy to read with Java 7double pi 3.14_15_92; //another example of readability } ... 是的没有什么新东西了……编译器只重写没有下划线的值并将二进制值转换为整数值 //in a class ... public static void coin( {int binaryNum 2;double value1 1000000000D;double value2 1000000000D;double value3 2743D;double value4 2743D;double pi 3.1415920000000002D; } ... 好的仅此而已。 希望大家都喜欢Java 7中的Project CoinJSR334的新功能。Java8中的Project Coin II还有更多改进我们将在以后的文章中进行检查。 再见 参考我们的JCG合作伙伴提供的 Java –项目硬币反编译和Java 7 –项目硬币反编译第二部分 Java和ME博客上的Alexis Lopez。 翻译自: https://www.javacodegeeks.com/2012/04/java-7-project-coin-decompiled.html
http://www.pierceye.com/news/439949/

相关文章:

  • 百度站长怎么验证网站jekyll做公司网站
  • 电子商务公司建设网站方案设计网站建设开发背景
  • 同一产品做多个网站山西省住房和城乡建设厅官网
  • 网站建设的流程是什么意思微信小程序的代码
  • 广州网站整站优化html项目案例实战
  • 宁波网站推广方式seo优化按天扣费
  • 紫金优化网站制作python编程100例
  • 原阳网站建设哪家好域名网址
  • 西安学校网站建设wordpress手机端模板下载
  • 泉州网站建设工作室网站上的产品板块
  • 平顶山网站网站建设网页设计与制作教程 刘瑞信 pdf
  • 网站开发深天津设计公司排行榜
  • 做tcf法语听力题的网站公司网页简介
  • 十堰做网站最专业的公司深圳企业网查询
  • 购物网站大全排名调查drupal与wordpress哪个容易
  • 网站建设彳金手指排名网站开发完没人运营
  • 网站建设是设开发公司质量管理流程
  • 金沙网站怎么做代理wordpress tag=
  • 做网站必须花钱吗建筑人才网证书查询
  • 0基础网站建设模板工商注册官方网站
  • 河南网站设计公司价格网站在建设中是什么意思
  • 网站建设公司的成本有哪些方面四川省城乡建设网查询
  • 和什么人合作做游戏视频网站做推送网站
  • 做竞价网站访问突然变少施工企业负责人带班检查计划
  • 网站统计数据分析wordpress安装 第二步
  • 网站续费续的是什么钱Wordpress1002无标题
  • 公司入口网站appui设计师创意平台
  • 济南住房和城乡建设厅网站影视广告创意拍摄
  • 卢松松网站源码网站建设讲师招聘
  • wordpress建站网页无法运vs网站开发表格大小设置