Map<Integer, Map<String, String>> mapMap = new HashMap<Integer,Map<String, String>>();
Run Code Online (Sandbox Code Playgroud)
目前断言这样
assertThat(mapMap.size(), is(equalTo(1)));
Or
assertThat(mapMap.values(), hasSize(1));
Run Code Online (Sandbox Code Playgroud)
是否有任何其他方法,如与列表一起使用的方法.
assertThat(someListReferenceVariable,hasSize(1));
我有一个重载方法,它将两个不同的功能接口作为参数(Runnble和Supplier).System.out.println显然只是兼容Runnable,因为它是一种void方法.然而,编译器仍然声称呼叫是模糊的.怎么可能?
import java.util.function.Supplier;
public class GenericLambdas {
public static void main(String[] args) {
wrap(System.out::println); // Compiler error here
wrap(() -> {}); // No error
wrap(System.out::flush); // No error
}
static <R> void wrap(Supplier<R> function) {}
static void wrap(Runnable function) {}
}
Run Code Online (Sandbox Code Playgroud)
编译器输出:
Error:Error:line (5)java: reference to wrap is ambiguous
both method <R>wrap(java.util.function.Supplier<R>) in GenericLambdas and method wrap(java.lang.Runnable) in GenericLambdas match
Error:Error:line (5)java: incompatible types: cannot infer type-variable(s) R
(argument mismatch; …Run Code Online (Sandbox Code Playgroud) 我知道 Dateadd 和 datediff,但我找不到如何在实际日期列上使用这些函数的任何信息,而不是像今天使用 SQL Server 的日期。
说我有以下专栏
Dated
06/30/2015
07/31/2015
Run Code Online (Sandbox Code Playgroud)
现在我想添加以下派生列,从 Dated 列中的每一行减去一个月。
Dated Subtracted
06/30/2015 05/31/2015
07/31/2015 06/30/2015
Run Code Online (Sandbox Code Playgroud)
谢谢
有没有办法使用别名或“功能标签”来指定 npm 中的依赖项子集?也就是说,如果有人知道他们只会使用我的包功能的某些有限子集,他们可以指定这些功能,并且npm install仅下载与这些功能相关的依赖项?
我的包有大量的依赖项,安装需要近半个小时,但大多数用户只需要其功能的子集。我正在考虑如何将依赖项分为 devDependency 和依赖项,但有 n 个组,而不仅仅是这两个组。例如:
npm install --feature feature1 --feature feature2
Run Code Online (Sandbox Code Playgroud)
通过阅读文档,我认为这里的答案是“否”,但是您对这种情况的建议是什么?将包拆分为更小的插件包并让用户安装他们想要的插件?我不想要用户配置过于复杂的东西。
我正在尝试创建一个相当简单的收集器,将a转换Stream<Map.Entry>为a Map,但javac正在抱怨泛型.无法弄清楚为什么它不起作用.
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class CollectorSO {
public static <K, V> void main(String[] args) {
Collector<Entry<K, V>, ?, Map<K, V>> collector = Collectors.toMap(Entry::getKey, Entry::getValue);
Stream<Entry<String, Object>> stream = Stream.empty();
Map<String, Object> map = stream.collect(collector);
}
}
Run Code Online (Sandbox Code Playgroud)
编译器输出:
Error:(11, 41) java: no suitable method found for collect(java.util.stream.Collector<java.util.Map.Entry<K,V>,capture#1 of ?,java.util.Map<K,V>>)
method java.util.stream.Stream.<R>collect(java.util.function.Supplier<R>,java.util.function.BiConsumer<R,? super java.util.Map.Entry<java.lang.String,java.lang.Object>>,java.util.function.BiConsumer<R,R>) is not applicable
(cannot infer type-variable(s) R
(actual and formal argument lists differ in …Run Code Online (Sandbox Code Playgroud) 尝试测试一种采用对象列表并返回对象排序列表的方法。排序是基于将第一个元素放在具有空字符串值的列表上而进行的。测试失败,并出现以下错误:
java.lang.AssertionError:
Unexpected method call LoggerConfig.getName():
LoggerConfig.getName(): expected: 1, actual: 2
Run Code Online (Sandbox Code Playgroud)
这里的问题是希望有明确的通话次数。在这里,似乎该方法被调用太多,这引发了一个异常,即该方法已被调用过多次。在第一个方法调用超出限制(从EasyMock指南中获取)后,立即发生故障。问题是在这种情况下如何解决?我在哪里做错了?
EasyMock代码:
public class SorterTest {
private Sorter tested;
LoggerConfig item1;
LoggerConfig item2;
LoggerConfig item3;
List<LoggerConfig> sortedList;
@Before
public void setUp() {
tested = new Sorter();
}
private List<LoggerConfig> makeUnsortedList() {
item1 = EasyMock.mock(LoggerConfig.class);
item2 = EasyMock.mock(LoggerConfig.class);
item3 = EasyMock.mock(LoggerConfig.class);
EasyMock.expect(item1.getName()).andReturn("com.core");
EasyMock.expect(item2.getName()).andReturn("");
EasyMock.expect(item3.getName()).andReturn("com.core.FOO");
List<LoggerConfig> unsortedList = new ArrayList<>();
unsortedList.add(item1);
unsortedList.add(item2);
unsortedList.add(item3);
return unsortedList;
}
@Test
public void testSort() {
List<LoggerConfig> unsortedList = makeUnsortedList();
EasyMock.replay(item1,item2,item3); …Run Code Online (Sandbox Code Playgroud) 我需要用%符号替换字符串中的空格,但我遇到了一些问题,我尝试的是:
imageUrl = imageUrl.replace(' ', "%20");
Run Code Online (Sandbox Code Playgroud)
但它在替换功能中给了我一个错误.
然后:
imageUrl = imageUrl.replace(' ', "%%20");
Run Code Online (Sandbox Code Playgroud)
但它仍然在替换功能中给我一个错误.
我尝试使用unicode符号:
imageUrl = imageUrl.replace(' ', (char) U+0025 + "20");
Run Code Online (Sandbox Code Playgroud)
但它仍然给出错误.
有一个简单的方法吗?
java ×5
java-8 ×2
collectors ×1
dateadd ×1
easymock ×1
generics ×1
hamcrest ×1
java-stream ×1
junit ×1
lambda ×1
npm ×1
npm-install ×1
package.json ×1
sql ×1
sql-server ×1