missing Return Statement

Status
Nicht offen für weitere Antworten.

dognose

Mitglied
Hallo,

vor 2 Tagen habe ich mit Java Angefangen, um mein Blackberry zu personalisieren.

Allerdings bekomme ich die folgende Fehlermeldung:
\bin\DynamicArrayOfTracks.java:25: missing return statement
}
^

hier die relevante klasse... (zeile 25 markiert)

Code:
public class DynamicArrayOfTracks {
    
       private Track[] data;  // An array to hold the data.
              
       public Track DynamicArrayOfTracks() {
              // Constructor.
          data = new Track[1];  // Array will grow as necessary.
       }
       
       public Track get(int position) {           //Zeile 25  <----------------------------
            if (position >= data.length){
                return null;
            }else{
                return data[position];
            }
       }
       
       public void put(int position, Track trackToAdd) {
             // Store the value in the specified position in the array.
             // The data array will increase in size to include this
             // position, if necessary.
          if (position >= data.length) {
                 // The specified position is outside the actual size of
                 // the data array.  Double the size, or if that still does
                 // not include the specified position, set the new size
                 // to 2*position. 
             int newSize = 2 * data.length;
             if (position >= newSize)
                newSize = 2 * position;
             Track[] newData = new Track[newSize];
             System.arraycopy(data, 0, newData, 0, data.length);
             data = newData;
          }
          data[position] = trackToAdd;
       }
    
    } // end class DynamicArrayOfTracks

Imho sind in der function Track doch alle codepfade durch if bzw else abgedeckt.
setze ich danach noch ein return, bekomme ich den fehler, dass das gar nicht erreichbar sein (was ja richtig ist)

grüße,
dognose
 
@x.l hat gesagt.:
Dein Konstruktor ist falsch, in Zeile 6 muss das Track weg.

😳 Yupp, so gehts. - Aber warum?

Also warum muss beim Konstruktor keinen return type angeben?

edit: Ah, klar, weil ich da ja gar nix returnen will, sondern lediglich ein statement ausführen möchte, oder ?

grüße
dognose
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben