Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31635
| From | Robbie Brown <rob@example.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: What is your favorite WC++IETJ? |
| Date | 2015-04-30 20:37 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <mhu088$b3a$1@dont-email.me> (permalink) |
| References | <WCIETJ-20150430130949@ram.dialup.fu-berlin.de> <mht8ic$20f$1@news.albasani.net> <abbreviations-20150430152141@ram.dialup.fu-berlin.de> <supertype-20150430155737@ram.dialup.fu-berlin.de> |
On 30/04/15 14:58, Stefan Ram wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> . Now, we want to generalize and omit some specializations
>> (details):
>> Set<Character> result = new HashSet<>();
>
> The general idea of an assignment in Java is:
>
> supertypeVariable = subtypeExpression
>
> , however in the case of
>
> Set<Character> result = new HashSet<>()
>
> now, confusingly, the more general designation »<>«
> appears on the right side, while the more special
> designation »<Character>« appears on the left side.
The generalization is on the left, the rhs is simply shorthand to stop
us having to write Set<Character> result = new HashSet<Character>()
which used to cause howls of protest from even experienced Java
developers. Try compiling Set<Character> result = new HashSet<Object>()
if the rhs was a generalization we should be able to generalize but we
can't.
HashSet<>() is not a generalization it is simply shorthand.
The Generalization Set<Character> allows for information hiding, a
fundamental concept behind the idea of encapsulation.
public Set getFoo(){
Set x = new HashSet();
...
return x;
}
the implementation of x can be changed without affecting clients of
getFoo();
Seems perfectly reasonable to me.
--
Not floundering ... just fishing
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: What is your favorite WC++IETJ? Sebastian <news@seyweiler.dyndns.org> - 2015-04-30 14:52 +0200 Re: What is your favorite WC++IETJ? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-30 10:03 -0400 Re: What is your favorite WC++IETJ? Jerry Stuckle <jstucklex@attglobal.net> - 2015-04-30 12:18 -0400 Re: What is your favorite WC++IETJ? Robbie Brown <rob@example.com> - 2015-04-30 20:37 +0100
csiph-web