Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31635

Re: What is your favorite WC++IETJ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Robbie Brown <rob@example.com>
Newsgroups comp.lang.java.programmer
Subject Re: What is your favorite WC++IETJ?
Date Thu, 30 Apr 2015 20:37:40 +0100
Organization A noiseless patient Spider
Lines 45
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>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Thu, 30 Apr 2015 19:36:40 +0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="1472fcbe5105b2f1a291b5cf6efc19de"; logging-data="11370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19kHMaRy5gEw1az3fBOtsh/8BL7IklOIMA="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
In-Reply-To <supertype-20150430155737@ram.dialup.fu-berlin.de>
Cancel-Lock sha1:OLc84yXIbx8iZJVUZJNrwiDdZpI=
Xref csiph.com comp.lang.java.programmer:31635

Show key headers only | View raw


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


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