• 请不要在回答技术问题时复制粘贴 AI 生成的内容
shiroikuma
V2EX  ›  程序员

一个简化标准输出的想法

  •  
  •   shiroikuma · Jun 7, 2019 via Android · 2560 views
    This topic created in 2559 days ago, the information mentioned may be changed or developed.
    在 Object 类下面添加一个函数,比如说
    void print(){
    System.out.println(this); //js c#类似
    }
    这样不是方面更多了吗,lambda 更简洁,还可以链式调用
    "hello world". print ()
    有没有语言是这样的
    7 replies    2019-06-08 18:17:36 +08:00
    runze
        1
    runze  
       Jun 7, 2019 via Android
    powershell?
    kaneg
        2
    kaneg  
       Jun 7, 2019 via iPhone
    System.out 输出在稍大点的项目中都是禁止的,在 Object 这么基础的类中加这个是大材小用了
    WispZhan
        3
    WispZhan  
       Jun 7, 2019
    随便一个支持"Extension Functions"的语言都没这个烦恼。
    shiroikuma
        4
    shiroikuma  
    OP
       Jun 7, 2019 via Android
    @kaneg 调试也很重要呐。能把 print 写进预置函数,为啥不能写进 object
    shiroikuma
        5
    shiroikuma  
    OP
       Jun 7, 2019 via Android
    @WispZhan 这个方案可以避免 print 里面东西太多挤在一起影响阅读体验
    luozic
        6
    luozic  
       Jun 7, 2019 via iPhone
    支持管道的语言,直接把栈里面的输出到管道不是更容易调试? 要么就直接上全局 tracid。
    temp178
        7
    temp178  
       Jun 8, 2019 via Android
    Object 类作为对象的父类,它的方法应该是和 对象 这个概念相关的,如 toString , hashcode,equals 等,而不是和业务相关的 print
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3435 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 11:44 · PVG 19:44 · LAX 04:44 · JFK 07:44
    ♥ Do have faith in what you're doing.