Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32746 > unrolled thread
| Started by | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| First post | 2015-10-01 08:24 -0400 |
| Last post | 2015-10-02 09:18 -0500 |
| Articles | 9 — 6 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: A small quiz Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-01 08:24 -0400
Re: A small quiz e.d.programmer@gmail.com - 2015-10-01 08:33 -0700
Re: A small quiz Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-01 11:41 -0400
Re: A small quiz Eric Douglas <e.d.programmer@gmail.com> - 2015-10-01 08:59 -0700
Re: A small quiz Jeff Higgins <jeff@invalid.invalid> - 2015-10-01 12:49 -0400
Re: A small quiz Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-01 13:02 -0400
Re: A small quiz Eric Douglas <e.d.programmer@gmail.com> - 2015-10-01 10:19 -0700
Thanks (Was: A small quiz) j4n bur53 <janburse@fastmail.fm> - 2015-10-02 00:12 +0200
Re: A small quiz Mike Amling <mamling@chaff.us> - 2015-10-02 09:18 -0500
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-10-01 08:24 -0400 |
| Subject | Re: A small quiz |
| Message-ID | <muj8i2$iuj$2@dont-email.me> |
On 10/1/2015 8:02 AM, Stefan Ram wrote:
> A method m() is declared to have a return type of java.lang.String:
>
> java.lang.String m()
>
> . A programmer writes this expression:
>
> java.lang.String.valueOf( m() )
>
> (The scope is so that »m« in the above expression refers to the
> method »m()« as declared above.)
>
> . Can you find out what might be a good reason the programmer might
> have to write this expression? Since the return type of m() already
> /is/ java.lang.String, the call to »java.lang.String.valueOf« seems
> to be completely superfluous!
Please don't use the N-word, Stefan.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [next] | [standalone]
| From | e.d.programmer@gmail.com |
|---|---|
| Date | 2015-10-01 08:33 -0700 |
| Message-ID | <c4e3bc51-840d-443c-ba12-b91b0e139d38@googlegroups.com> |
| In reply to | #32746 |
On Thursday, October 1, 2015 at 8:24:36 AM UTC-4, Eric Sosman wrote: > Please don't use the N-word, Stefan. Which N-word, null? Somehow I don't see the original message you're replying on.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-10-01 11:41 -0400 |
| Message-ID | <mujk3i$3j8$1@dont-email.me> |
| In reply to | #32751 |
On 10/1/2015 11:33 AM, e.d.programmer@gmail.com wrote:
> On Thursday, October 1, 2015 at 8:24:36 AM UTC-4, Eric Sosman wrote:
>> Please don't use the N-word, Stefan.
>
> Which N-word, null?
Give the man a cigar!
> Somehow I don't see the original message you're replying on.
Can't help you, I'm afraid. Possibly something to do with
Stefan's fondness for the X-No-Archive header and similar
"implausible deniability" measures.
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2015-10-01 08:59 -0700 |
| Message-ID | <45bae432-2df5-4878-832b-11c465d666d8@googlegroups.com> |
| In reply to | #32752 |
On Thursday, October 1, 2015 at 11:41:49 AM UTC-4, Eric Sosman wrote:
> > Which N-word, null?
>
> Give the man a cigar!
>
> > Somehow I don't see the original message you're replying on.
>
> Can't help you, I'm afraid. Possibly something to do with
> Stefan's fondness for the X-No-Archive header and similar
> "implausible deniability" measures.
That could explain it. Did you see his message on a Google Group reader, or an email distribution list?
So the valueOf is pointless?
I tried this little test program:
public static void main(String[] args) {
String s = null;
System.out.println(s);
System.out.println(String.valueOf(s));
System.out.println(String.valueOf(null));
}
It didn't crash until it tried to get the valueOf the constant.
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2015-10-01 12:49 -0400 |
| Message-ID | <mujo2p$jtr$1@dont-email.me> |
| In reply to | #32753 |
On 10/01/2015 11:59 AM, Eric Douglas wrote:
>
> So the valueOf is pointless?
> I tried this little test program:
> public static void main(String[] args) {
> String s = null;
> System.out.println(s);
> System.out.println(String.valueOf(s));
> System.out.println(String.valueOf(null));
> }
> It didn't crash until it tried to get the valueOf the constant.
>
It would have, hadn't PrintStream checked for a null.
public void print(String s) {
if (s == null) {
s = "null";
}
write(s);
}
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-10-01 13:02 -0400 |
| Message-ID | <mujoqo$mnr$1@dont-email.me> |
| In reply to | #32753 |
On 10/1/2015 11:59 AM, Eric Douglas wrote:
> On Thursday, October 1, 2015 at 11:41:49 AM UTC-4, Eric Sosman wrote:
>>> Which N-word, null?
>>
>> Give the man a cigar!
>>
>>> Somehow I don't see the original message you're replying on.
>>
>> Can't help you, I'm afraid. Possibly something to do with
>> Stefan's fondness for the X-No-Archive header and similar
>> "implausible deniability" measures.
>
> That could explain it. Did you see his message on a Google Group reader, or an email distribution list?
Neither: I used Thunderbird and news.eternal-september.org's
NNTP server.
> So the valueOf is pointless?
> I tried this little test program:
> public static void main(String[] args) {
> String s = null;
> System.out.println(s);
> System.out.println(String.valueOf(s));
> System.out.println(String.valueOf(null));
> }
> It didn't crash until it tried to get the valueOf the constant.
A subtler quiz might be: Why does the final line crash when
the preceding line doesn't? (And a further debate: Is the crash
a bug, or a feature, or a misfeature?)
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2015-10-01 10:19 -0700 |
| Message-ID | <a93a2c6f-706a-4d08-8c1c-d54de4d33443@googlegroups.com> |
| In reply to | #32755 |
On Thursday, October 1, 2015 at 1:02:17 PM UTC-4, Eric Sosman wrote: > A subtler quiz might be: Why does the final line crash when > the preceding line doesn't? (And a further debate: Is the crash > a bug, or a feature, or a misfeature?) Error is Exception in thread "main" java.lang.NullPointerException at java.lang.String.<init>(Unknown Source) at java.lang.String.valueOf(Unknown Source) Why does passing in a null constant generate this runtime error, and not a compile error? It's just a confusing use of overload. http://stackoverflow.com/questions/3131865/why-does-string-valueofnull-throw-a-nullpointerexception
[toc] | [prev] | [next] | [standalone]
| From | j4n bur53 <janburse@fastmail.fm> |
|---|---|
| Date | 2015-10-02 00:12 +0200 |
| Subject | Thanks (Was: A small quiz) |
| Message-ID | <mukb49$sub$1@news.albasani.net> |
| In reply to | #32756 |
Eric Douglas schrieb: > Why does passing in a null constant generate this runtime error, and not a compile error? > It's just a confusing use of overload. > http://stackoverflow.com/questions/3131865/why-does-string-valueofnull-throw-a-nullpointerexception Was just wondering how long it takes me to find the Java language choice rule for overloaded Java class members. And here it is. Currently doing an experiment in Prolog to Java scripting, and need to code a dispatcher. An ad-hoc dispatcher which uses the input order of the Java class members already works: Better Modules: An auto loader for overloaded members. (Jekejeke) https://plus.google.com/+JekejekeCh/posts/SANxqdzvUaz But I guess sooner or later I will need something more intelligent and closer to the Java language rules. Respecting the implements relation ship of the base class to its super class is also on the todo list.
[toc] | [prev] | [next] | [standalone]
| From | Mike Amling <mamling@chaff.us> |
|---|---|
| Date | 2015-10-02 09:18 -0500 |
| Message-ID | <mum3fg$h7b$1@dont-email.me> |
| In reply to | #32756 |
On 10/1/15 12:19 PM, Eric Douglas wrote: > On Thursday, October 1, 2015 at 1:02:17 PM UTC-4, Eric Sosman wrote: >> A subtler quiz might be: Why does the final line crash when >> the preceding line doesn't? (And a further debate: Is the crash >> a bug, or a feature, or a misfeature?) > > Error is > Exception in thread "main" java.lang.NullPointerException > at java.lang.String.<init>(Unknown Source) > at java.lang.String.valueOf(Unknown Source) > > Why does passing in a null constant generate this runtime error, and not a compile error? > It's just a confusing use of overload. > http://stackoverflow.com/questions/3131865/why-does-string-valueofnull-throw-a-nullpointerexception To preclude an unexpected choice of "Most Specific Method", I recommend always casting a null literal when used as a method argument. System.out.println(String.valueOf((String)null)); // Prints "null". System.out.println(String.valueOf((Object)null)); // Prints "null". System.out.println(String.valueOf(null)); // NullPointerException Mike Amling RXZlbiB3aGVuIHRoZSBtZXRob2QgaXNuJ3Qgb3ZlcmxvYWRlZC4=
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web