Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

new Socket ((SocketImpl) null) ???  RSS feed

 
Ken Hanks
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to figure out how the "accept" method of ServerSocket just sits there and blocks. In looking at it, I noticed that "accept" creates a Socket ref var with this code: Socket s = new Socket((SocketImpl) null);
The question is, does this mean that a null reference variable, cast to type SocketImpl, is being passed to the Socket constructor? If so, I have to wonder why they did it that way....
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks as if it were just done for readability, so you'd know what the "null" represented; there's only one Socket constructor that takes a reference object, so the cast is unnecessary.

Interestingly, in JDK1.3 and earlier, the no-argument Socket constructor is used instead.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!