• Post Reply Bookmark Topic Watch Topic
  • New Topic

a reference from a method?  RSS feed

 
cameron fraser
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone explain what exactly is going on in this statement?

Sequencer sequencer = MidiSystem.getSequencer();

Am I thinking correctly about this statement? You are creating a reference variable called "sequencer" to the Sequencer Interface, yet its calling a method?

I am understanding of object creation and polymorphism such as: Sequencer sequencer = new Sequencer(); or Animal a = new lizard(); But here I am a bit confused to what is going on.

 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what exactly is going on in this statement?

Sequencer sequencer = MidiSystem.getSequencer();

Start by reading the API doc for the MidiSystem class.

My guess on what that statement does is:
calls the static method: getSequence() in the MidiSystem class,
that method returns a reference to a Sequencer object
 
Sankalp Bhagat
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't read the API but from the line given by you

a static method getSequencer() is declared in MidiSystem class whose return type is Sequencer. So, when you call getSequencer() method, it returns Sequencer class's object. Thus, you have to hold that object in a reference. That's why you are taking "Sequencer sequencer" to hold the returned Sequencer object in a reference variable called "sequencer"
 
Stevens Miller
Bartender
Posts: 1445
30
C++ Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, cameron. Here's what the Javadoc says:

public static Sequencer getSequencer() throws MidiUnavailableException

Obtains the default Sequencer, connected to a default device. The returned Sequencer instance is connected to the default Synthesizer, as returned by getSynthesizer(). If there is no Synthesizer available, or the default Synthesizer cannot be opened, the sequencer is connected to the default Receiver, as returned by getReceiver(). The connection is made by retrieving a Transmitter instance from the Sequencer and setting its Receiver. Closing and re-opening the sequencer will restore the connection to the default device.

This method is equivalent to calling getSequencer(true).

If the system property javax.sound.midi.Sequencer is defined or it is defined in the file "sound.properties", it is used to identify the default sequencer. For details, refer to the class description.

Returns:
the default sequencer, connected to a default Receiver

Does that make sense to you, or do you need some help in understanding it?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!