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

一个简化标准输出的想法

  •  
  •   shiroikuma · Jun 7, 2019 via Android · 2872 views
    This topic created in 2708 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
    runze
    Jun 7, 2019 via Android
    1
    powershell?
    kaneg
    kaneg
    Jun 7, 2019 via iPhone
    2
    System.out 输出在稍大点的项目中都是禁止的,在 Object 这么基础的类中加这个是大材小用了
    WispZhan
    WispZhan
    Jun 7, 2019
    3
    随便一个支持"Extension Functions"的语言都没这个烦恼。
    shiroikuma
    shiroikuma
    OP
    Jun 7, 2019 via Android
    4
    @kaneg 调试也很重要呐。能把 print 写进预置函数,为啥不能写进 object
    shiroikuma
    shiroikuma
    OP
    Jun 7, 2019 via Android
    5
    @WispZhan 这个方案可以避免 print 里面东西太多挤在一起影响阅读体验
    luozic
    luozic
    Jun 7, 2019 via iPhone
    6
    支持管道的语言,直接把栈里面的输出到管道不是更容易调试? 要么就直接上全局 tracid。
    temp178
    temp178
    Jun 8, 2019 via Android
    7
    Object 类作为对象的父类,它的方法应该是和 对象 这个概念相关的,如 toString , hashcode,equals 等,而不是和业务相关的 print
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1911 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 16:50 · PVG 00:50 · LAX 08:50 · JFK 11:50
    ♥ Do have faith in what you're doing.