【问题标题】:How to resolve "The expression of type Class needs unchecked conversion to conform to Class<Object>" [duplicate]如何解决“Class 类型的表达式需要未经检查的转换以符合 Class<Object>” [重复]
【发布时间】:2014-05-14 00:57:51
【问题描述】:

我有 ff。测试方法:

@Mock
private DBAccessor accessor;

/**
 * Successful find().
 */
@Test
public void testFind() {
    // Prepare
    MockDto mockDto = mock(MockDto.class);
    try {
        when(accessor.executeQuery(any(Class.class), anyString(), any(ConcurrentHashMap.class))).thenReturn(
                mockDto);
    } catch (Exception e) {
        fail("Unexpected exception.");
    }
}

然而,ff.出现警告:

Multiple markers at this line
    - Type safety: Unchecked invocation executeQuery(Class, String, ConcurrentHashMap) of the generic method executeQuery(Class<T>, String, Object) of type DBAccessor
    - Type safety: The expression of type Class needs unchecked conversion to conform to Class<Object>

如何解决上述警告?

我使用 Mockit 和 Powermock 作为模拟框架和 JUnit。

【问题讨论】:

标签: java junit mockito powermock data-access


【解决方案1】:

如 ff 中所示。 post,可以通过@SuppressWarnings("unchecked")删除。

【讨论】:

    猜你喜欢
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多