{"action":"created","issue":{"url":"https://api.github.com/repos/jcoplien/trygve/issues/21","labels_url":"https://api.github.com/repos/jcoplien/trygve/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/jcoplien/trygve/issues/21/comments","events_url":"https://api.github.com/repos/jcoplien/trygve/issues/21/events","html_url":"https://github.com/jcoplien/trygve/issues/21","id":123957871,"number":21,"title":"Automatically call toString if it exists?","user":{"login":"ciscoheat","id":130450,"avatar_url":"https://avatars.githubusercontent.com/u/130450?v=3","gravatar_id":"","url":"https://api.github.com/users/ciscoheat","html_url":"https://github.com/ciscoheat","followers_url":"https://api.github.com/users/ciscoheat/followers","following_url":"https://api.github.com/users/ciscoheat/following{/other_user}","gists_url":"https://api.github.com/users/ciscoheat/gists{/gist_id}","starred_url":"https://api.github.com/users/ciscoheat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciscoheat/subscriptions","organizations_url":"https://api.github.com/users/ciscoheat/orgs","repos_url":"https://api.github.com/users/ciscoheat/repos","events_url":"https://api.github.com/users/ciscoheat/events{/privacy}","received_events_url":"https://api.github.com/users/ciscoheat/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-27T03:15:09Z","updated_at":"2015-12-27T12:12:05Z","closed_at":null,"body":"Would it be possible to automatically use `toString` for an object if that method is defined (as Java does), so you can make things like:\r\n\r\n```\r\nComplexNumber a = new ComplexNumber(1.0, -2.0);\r\nSystem.out.println(a); // outputs 1.0-2.0im\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/jcoplien/trygve/issues/comments/167404800","html_url":"https://github.com/jcoplien/trygve/issues/21#issuecomment-167404800","issue_url":"https://api.github.com/repos/jcoplien/trygve/issues/21","id":167404800,"user":{"login":"jcoplien","id":7209130,"avatar_url":"https://avatars.githubusercontent.com/u/7209130?v=3","gravatar_id":"","url":"https://api.github.com/users/jcoplien","html_url":"https://github.com/jcoplien","followers_url":"https://api.github.com/users/jcoplien/followers","following_url":"https://api.github.com/users/jcoplien/following{/other_user}","gists_url":"https://api.github.com/users/jcoplien/gists{/gist_id}","starred_url":"https://api.github.com/users/jcoplien/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcoplien/subscriptions","organizations_url":"https://api.github.com/users/jcoplien/orgs","repos_url":"https://api.github.com/users/jcoplien/repos","events_url":"https://api.github.com/users/jcoplien/events{/privacy}","received_events_url":"https://api.github.com/users/jcoplien/received_events","type":"User","site_admin":false},"created_at":"2015-12-27T12:12:05Z","updated_at":"2015-12-27T12:12:05Z","body":"\n> Den 27/12/2015 kl. 04.15 skrev Andreas <notifications@github.com>:\n> \n> Would it be possible to automatically use toString for an object if that method is defined (as Java does), so you can make things like:\n> \n> ComplexNumber a = new ComplexNumber(10, -20);\n> Systemoutprintln(a); // outputs 10-20im\nMaybe. For this particular approach I might prefer:\n\n        ComplexNumber a = new ComplexNumber(10, -20);\n    System.out.println((String)a)\n\nYou of course can define the toString method and then just do this;\n\n\tComplexNumber a = new ComplexNumber(10, -20);\n\tSystem.out.println(a.toString())\n\nBut I/O in general may require more careful thinking. I don’t like the whole Java approach. The C++ approach is more ideologically sound but it’s quite complicated. I suspect that in the long term I may end up trying something along the lines of multiple dispatch (on a PrintStream and an object), which borrows heavily from the C++ approach (but which is complex in part because C++ doesn’t support multi-methods)."}}