首页 > 解决方案 > 键入列表的第一个/第二个/第三个参数

问题描述

我正在考虑使用 List 作为元组,我想做类似的事情:

t.done(null, List.of(true, "some string");

有没有办法输入列表,所以第一个元素必须是布尔值,第二个元素必须是字符串?

标签: javatuples

解决方案


不知道为什么要为此使用列表。如果你认为一个专门的类太费力,你可以尝试使用Triple<L,M,R>Apache commons-lang:

Triple<Boolean, String, String> test = Triple.of(true, "some string", "another string");

推荐阅读