Questions tagged [effective-java]

Effective Java is a book by Joshua Bloch "designed to help Java programmers make the most effective use of the Java programming language and its fundamental libraries"

Effective Java is a book by Joshua Bloch of patterns "designed to help Java programmers make the most effective use of the Java programming language and its fundamental libraries".

178 questions
1
vote
1 answer

Java: why class designed for inheritance should contain protected clone method?

I'm reading carefully Effective Java (by Joshua Bloch) and I found the following sentence on cloning: If you design a class for inheritance, be aware that if you choose not to provide a well-behaved protected clone method, it will be impossible for…
agienka
  • 396
  • 1
  • 2
  • 11
1
vote
2 answers

Examples for combinatorial explosion in Java?

In the Effective Java, Item - 18, Bloch says that interfaces prevent combinatorial explosion, which will happen when using abstract classes with multiple attributes in a type system. I am not able to wrap my head around what exactly is combinatorial…
Aravamudhan
  • 198
  • 2
  • 11
1
vote
1 answer

Adding new methods to superclasses and resulting problems -Likelihood?

Item 16 of Effective Java 2nd edition, favor composition over inheritance says the following "If the superclass acquires a new method in a subsequent release and you have the bad luck to have given the subclass a method with the same signature and a…
1
vote
1 answer

Effective Java: Builder Pattern

I was reading Effective java item# 2- The Builder pattern http://www.informit.com/articles/article.aspx?p=1216151&seqNum=2 It is said here that java bean is not an effective way to create the object with multiple parameters. But what if I have the…
Rajan
  • 124
  • 2
  • 12
1
vote
3 answers

Keeping a value class non-final for possible future extensibility

I am creating a very simple class called Catalog. It will be an immutable class and have an id and name field. Out of habit, since I am not going to explicitly document this thing for extensibility, I put the final modifier on the class. However…
1
vote
3 answers

Use builder pattern for methods with many parameters?

I've read a recommendation in "Effective Java" to use the Builder pattern when faced with constructors that use lots of parameters. Does the same pattern apply to methods with lots of parameters ?
blue-sky
  • 51,962
  • 152
  • 427
  • 752
1
vote
2 answers

What is meant by proper declaration of read resolve method in the Effective Java book?

From the Serialization chapter of Effective Java: If the class of an object being deserialized defines a readResolve method with the proper declaration, this method is invoked on the newly created object after it is deserialized. The example…
Geek
  • 26,489
  • 43
  • 149
  • 227
1
vote
2 answers

Refer to objects by their interfaces. Always?

A cut code from effective java, here we used a List to obey the good practice of referring to objects by their interface. // Good - uses interface as type List subscribers = new Vector(); Assuming we had a car interface and…
JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132
1
vote
5 answers

Java Generics (bounded wildcards)

According to the book "Effective Java" of Joshua Bloch there is a rule about how/when use the bounded wildcards in generics. This rule is PECS (Producer-Extends, Comsumer-Super). When I study the following example: Stack numberStack = new…
LiTTle
  • 1,811
  • 1
  • 20
  • 37
1
vote
2 answers

Understanding Effective Java deep copy example

In Effective Java, 2nd Edition, Item 11 one can find the following deep copy example: public class HashTable implements Cloneable { private Entry[] buckets = ...; private static class Entry { final Object key; Object value; …
stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
1
vote
1 answer

Finalisers, closing files and streams

In Joshua Bloch's book "Effective Java" item 7 second edition he advises to avoid using finally statements particularly for closing files he says "it is a grave error to depend on a finaliser to close files". Two pages later he says that one of the…
Codey McCodeface
  • 2,988
  • 6
  • 30
  • 55
1
vote
6 answers

Why this generic method call is not working?

The following code is from Effective Java book : Set integers = ... ; Set doubles = ... ; Set numbers = union(integers, doubles); This code didn't compile and the author suggests to get around this problem by telling the…
Geek
  • 26,489
  • 43
  • 149
  • 227
1
vote
2 answers

Lazy initialization using single check idiom

In Item 71 in 'Effective Java, Second Edition' the Double-check idiom and the single-check idiom are introduced for lazily instantiating instance fields. Double-check idiom private volatile FieldType field; FieldType getField() { FieldType result…
Will
  • 2,858
  • 6
  • 33
  • 50
1
vote
1 answer

An example of the internals of a immutable class being shared in other related classes in core Java

One of the many advantages of an immutable class is that their internals can actually be shared somehow in other related classes. What can be cited as an example of this technique from core java library ? Why does this technique work ? Edit : This…
Geek
  • 26,489
  • 43
  • 149
  • 227
1
vote
3 answers

Effective Java. Clonable interface

I read Effective Java book and don't understand one paragraph where explained Clonable interface. Can someone explain me this paragraph: ...programmers assume that if they extend a class and invoke super.clone from the subclass, the returned…
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286