V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
dumbbell5kg
V2EX  ›  程序员

请教一个 Java Stream 中代码命名的问题

  •  
  •   dumbbell5kg · 2022-09-23 18:03:33 +08:00 · 971 次点击
    这是一个创建于 571 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在看 Stream 的代码,有些命名不理解: 比如 SortedOps 类中

    final class SortedOps {
    
        private SortedOps() { }
        
      	1.//这里应该是 make reference
        static <T> Stream<T> makeRef(AbstractPipeline<?, T, ?> upstream) {
            return new OfRef<>(upstream);
        }
        
        2.//这里是 make int reference
        static <T> IntStream makeInt(AbstractPipeline<?, Integer, ?> upstream) {
            return new OfInt(upstream);
        }
        
        3.//这里的子类为什么要叫 OfRef 呀?
        private static final class OfRef<T> extends ReferencePipeline.StatefulOp<T, T> {}
         
        4.//这里为什么要叫 OfInt ?
        private static final class OfInt extends IntPipeline.StatefulOp<Integer> {}
     }
    
    2 条回复    2022-09-25 10:23:51 +08:00
    xaplux
        1
    xaplux  
       2022-09-24 10:25:44 +08:00
    我理解这里的 Of 有组成的意思吧,比如 List.of(1,2,3),代码这个 list 是由 1,2,3 组成的
    dumbbell5kg
        2
    dumbbell5kg  
    OP
       2022-09-25 10:23:51 +08:00
    @xaplux 这么想就好理解多了,感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1820 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:32 · PVG 00:32 · LAX 09:32 · JFK 12:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.