Maven依赖中的scope详解
Maven的一个设计范式是约定优于配置(convention over configuration), Maven默认的依赖配置项中,scope的默认值是compile,项目中经常傻傻的分不清,直接默认了。今天梳理一下maven的scope。 scope的分类compile默认就是compile,什么都不配置也就是意味着compile。compile表示被依赖项目需要参与当前项目的编译,当然后续的测试,运行周期也参与其中,是一个比较强的依赖。 providedprovided意味着打包的时候可以不用包进去,别的设施(如JDK或者容器)会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。相当于compile,但是在打包阶段做了exclude的动作。 runntimerunntime表示被依赖项不是编译所必需的,而是执行所必需的。与compile相比,跳过编译而已,说实话在终端的项目(非开源,企业内部系统)中,和compile区别不是很大。比较常见的如JSR×××的实现,对应的API...
Java中关于try、catch、finally中的细节分析
前言阿里巴巴开发手册中有这么一条:【强制】不要在 finally 块中使用 return , 在开发过程中发现部分同学对这条规则理解不是很透彻,本文将就 try 、catch、finally 的一些问题,分析一下 try 、catch、finally 的处理流程。 首先看一个例子: 例11234567891011121314151617181920public class TryCatchFinally { public static String test() { String t = ""; try { t = "try"; return t; } catch (Exception e) { t = "catch"; return t; } finally { t =...
Java小数点数字和百分号数字之间的转换
小数点数字和百分号(百分比)需要进行两者之间相互转换。如代码: 1234567891011121314151617181920212223242526String s1 = "21.8%";String s2 = "-21.7%"; NumberFormat numberFormat = NumberFormat.getPercentInstance();try { Number n1 = numberFormat.parse(s1); Number n2 = numberFormat.parse(s2); Log.d("小数点字符串转百分数", n1.floatValue() + " , " + n2.floatValue()); // 小数点字符串转百分数: 0.218 , -0.217} catch (Exception e) { e.printStackTrace();} float f1 = 0.218f;float...