有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何注册java。util。apacheflink中的列表类型

是否可以将Environment#registerType用于java.util.List或其他集合类型? 如果我这样做:

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

env.getConfig().disableGenericTypes();
env.registerType(List.class);

我仍然得到Generic types have been disabled in the ExecutionConfig and type java.util.List is treated as a generic type.

我确实想做的是,但由于类型擦除,在Java中不可能做到的是:

StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

env.getConfig().disableGenericTypes();
env.registerType(List<MyClass>.class);

不幸的是,我在文档中或使用搜索引擎时没有找到解决方案


共 (1) 个答案

  1. # 1 楼答案

    像这样实现List<T>怎么样

    class MyClassList implements List<MyClass> {
    ...
    }
    
    

    然后,您可以使用specifict MyClass注册类型MyClassList