将lambda表达式转换为java 7

nkkqxpd9  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(466)

我想利用这个站点提供的工具,基本上能够获取简单的pojo类,并输出生成的junit测试。但是,代码使用Java8(需要是Java7)。Java7等价于下面的代码段是什么?需要转换的主要是lambda表达式。
代码:
公共抽象类dtotest{

/**A map of default mappers for common objects. */
private static final ImmutableMap<Class<?>, Supplier<t>> DEFAULT_MAPPERS;

static {
    final Builder<Class<?>, Supplier<?>> mapperBuilder = ImmutableMap.builder();

    /* Primitives */
    mapperBuilder.put(int.class, () -> 0);
    mapperBuilder.put(double.class, () -> 0.0d);
    mapperBuilder.put(float.class, () -> 0.0f);
    mapperBuilder.put(long.class, () -> 0l);
    mapperBuilder.put(boolean.class, () -> true);
    mapperBuilder.put(short.class, () -> (short) 0);
    mapperBuilder.put(byte.class, () -> (byte) 0);
    mapperBuilder.put(char.class, () -> (char) 0);

    mapperBuilder.put(Integer.class, () -> Integer.valueOf(0));
    mapperBuilder.put(Double.class, () -> Double.valueOf(0.0));
    mapperBuilder.put(Float.class, () -> Float.valueOf(0.0f));
    mapperBuilder.put(Long.class, () -> Long.valueOf(0));
    mapperBuilder.put(Boolean.class, () -> Boolean.TRUE);
    mapperBuilder.put(Short.class, () -> Short.valueOf((short) 0));
    mapperBuilder.put(Byte.class, () -> Byte.valueOf((byte) 0));
    mapperBuilder.put(Character.class, () -> Character.valueOf((char) 0));

    mapperBuilder.put(BigDecimal.class, () -> BigDecimal.ONE);
    mapperBuilder.put(Date.class, () -> new Date());

    /* Collection Types. */
    mapperBuilder.put(Set.class, () -> Collections.emptySet());
    mapperBuilder.put(SortedSet.class, () -> Collections.emptySortedSet());
    mapperBuilder.put(List.class, () -> Collections.emptyList());
    mapperBuilder.put(Map.class, () -> Collections.emptyMap());
    mapperBuilder.put(SortedMap.class, () -> Collections.emptySortedMap());

    DEFAULT_MAPPERS = mapperBuilder.build();
}
kupeojn6

kupeojn61#

如果使用intellij,可以使用expand表达式。alt+enter->展开lambda

相关问题