idea提示那些事
来源:互联网 发布:windows pyqt5 教程 编辑:程序博客网 时间:2024/06/05 17:21
在用idea编程过程中会产生许多worning提示,细细查看这些提示,会得到许多好处:
- 优化代码,解除潜在bug
- 学习相关语言语法
现在把遇到的warning作总结如下。
求Array大小时候建议用length
Replace .size with .length on arrays and strings less
This inspection reports array.size and string.size calls. While such calls are legitimate, they require an additional implicit conversion to SeqLike to be made. A common use case would be calling length on arrays and strings may provide significant advantages.
Before:
Array(1, 2, 3, 4).size
"this is a string".size
After:
Array(1, 2, 3, 4).length
"this is a string".length
在求Array数量的时候建议用length函数提升效率
s字符串中包含变量时不加括号
val ss = "not find"
println(s"The error is ${ss}.")变为
println(s"The error is $ss.")
函数推导式不用加大括号
case _:Exception => {
log.error(s"wrong instruction : $s")
return Map()
}
应该为 case _:Exception =>
log.error(s"wrong instruction : $s")
return Map()
Map取值
Replace with .(key) less... (⌘F1)
Removes unnecessary gets when getting a value from map given a key.
Before:
map.get(k).get
After:
map(k)
直接用key从map中取值
调用无参函数
Java accessor method called as empty-paren less... (⌘F1)
Methods that follow JavaBean naming contract for accessors are expected to have no side effects. The recommended convention is to use a parameterless method whenever there are no parameters and the method have no side effect. This convention supports the uniform access principle, which says that client code should not be affected by a decision to implement an attribute as a field or method. The problem is that Java does not implement the uniform access principle. To bridge that gap, Scala allows you to leave off the empty parentheses on an invocation of function that takes no arguments.
* Refer to Programming in Scala, 10.3 Defining parameterless methods
在scala中调用无参函数或者调用java的无参函数都不必加括号
- idea提示那些事
- Intellij idea mybatis 插件 freeMybatisPlugin和 MybatisTools那些事
- IDEA重复代码提示
- idea提示忽略大小写
- IDEA 提示全无
- idea增加extjs提示
- idea的那些坑(1)
- idea 修改智能提示快捷键
- IntelliJ IDEA 代码提示快捷键
- idea序列化自动提示
- Intellij Idea @Autowired取消提示
- idea 14提示override错误
- idea 自动提示生成 serialVersionUID
- Intellij idea智能提示设置
- IDEA 关闭错误代码检测提示
- Intellij idea智能提示设置
- idea关闭重复代码提示
- IDEA 提示jar包问题
- Android listview 中嵌套 listview
- Unsupported gpu architecture 'compute_*'2017解决方法
- JAVA基础语法——API是什么——正则表达式
- 推荐的四款产品原型设计工具
- Android Service(服务)绑定远程服务一个小demo
- idea提示那些事
- 面向对象
- hiho-1015- KMP算法
- oop &&GP 模板 ---> 特化和偏特化
- 归并排序
- Docker容器: 那些你不知道的事
- 友元函数和static类
- 搭建Spring SpringMVC Mybatis 框架(二)
- 服务(service)-----本地服务