imcompatible types
import java.util.ArrayList;
public class song
{
private String name;
private String artist;
private int length;
private String genre;
private ArrayList ar = new ArrayList();
private ArrayList genreAL= new ArrayList();
public song()//default constructor
{
}
public song(String myName, String myArtist, int myLength, String myGenre )
{
name=myName;
artist=myArtist;
length=myLength;
genre=myGenre;
}
public void song(song ex)
{
name=ex.name;
artist=ex.artist;
length=ex.length;
genre=ex.genre;
}
public void setName(String ex)
{
name=ex;
}
public void setArtist(String ex)
{
artist=ex;
}
public void setLength(int ex)
{
length=ex;
}
public void setGenre(String ex)
{
genre=ex;
}
public String toString()
{
return "Song name: " + name+ " artist: "+artist+ " length: " +length+" genre: "+genre;
}
public String getGenre()
{
return genre;
}
public ArrayList specificGenre(String certainGenre)
{
for (int i =0; i <ar.size();i++)
{
if( ((((song)ar.get(i))).getGenre()).compareTo(certainGenre))
genreAL.add(ar.get(i));
}return genreAL;
}
}
i get an error in the last method. Im trying to get all the songs with a certain genre into an arraylist. not sure if my logic is right but i get incompatible types, not sure what the error is. certainGenre is a string and (song)ar.get(i).getGenre() should get me the genre of the song which should be also a string. so im not sure>

