package soundsystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class CDPlayer {
private CompactDisc cd;
@Autowired
public CDPlayer(CompactDisc cd) {
this.cd = cd;
}
public void play() {
cd.play();
}
}
Jaki sens ma użycie tego @Autowired w metodzie? Przecież i tak przy tworzeniu obiektu tej klasy muszę w argumencie podać obiekt CompactDisc?
@Autowired
private CompactDisc cd;
/*.
.
.
.
*/
CDPlayer use = new CDPlayer(cd);
use.play();
Shalom