List<String> sList = new ArrayList<>(3);
sList.add("a");
sList.add("b");
sList.add("c");
// before 1.5
for (int i = 0; i < 3; i++) {
System.out.println(sList.get(i));
}
// 1.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FilteringApples { | |
public static List<Apple> filterGreenApple(List<Apple> inventory) { | |
List<Apple> result = new ArrayList<>(); | |
for (Apple apple : inventory) { | |
if ("green".equals(apple.getColor())) { | |
result.add(apple); | |
} | |
} | |
return result; |
在泛型代码内部,无法获得任何有关泛型参数类型的信息。
泛型类型只有在静态类型检查期间才会出现,在此之后,程序中所有的泛型类型都将被擦除,替换为他们的非泛型上界。例如,List<T>
将被擦除为List
,而普通的类型变量在未指定边界的情况下将被擦除为Object
。
擦除主要的正当理由是从非泛化代码到泛化代码的转变过程,以及在不破坏现有类库的情况下,将泛型融入Java语言。向后兼容性
擦除的代价是显著的。泛型不能用于显式地引用运行时类型的操作之中,例如转型、instanceof
操作和new
表达式,因为所有关于参数的类型信息都丢失了。
@RequestMapping(path = "/", method = GET)
public String index(Model model)
throws Exception {
logger.info("processed by index");
model.addAttribute("msg", "GOGOGO");
return "go.jsp";
}
查看git上个人代码量
git log --author="username" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -
统计每个人的增删行数
git log --format='%aN' | sort -u | while read name; do echo -en "$name\t"; git log --author="$name" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -; done
查看仓库提交者排名前 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedList; | |
public class Main { | |
public static void main(String[] args) { | |
} | |
boolean bfs(Node start, Node end) { | |
LinkedList<Node> queue = new LinkedList<>(); |
查看用户组
cat /etc/group
查看所有用户
cat /etc/passwd
创建用户:
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
删除用户:
DROP USER 'username'@'host';
授权:
用update-rc.d命令给Debian添加开机启动项 Linux系统设置开机启动有很多方法,网上也有许多详细教程。本文只关注用update-rc.d命令给Debian添加开机启动。
例如:将test.sh脚本添加到开机自启。
1.将test.sh脚本放到/etc/init.d/
目录下
cp test.sh /etc/init.d/
cd /etc/init.d/
chmod +x test.sh