Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Buschmaster

macrumors 65816
Original poster
Feb 12, 2006
1,306
27
Minnesota
So, I'm quite confused by AbstractList and I'm working on an assignment for a class. Basically what we're doing is creating a catalog for a library where it will store the information such as title, ISBN, etc.

I am getting all the information in correctly and creating objects in the appropriate classes, but I don't know how to work AbstractList very well. Here's what I have so far...

BookList.java
[CODE ]import java.util.*;
import java.io.*;
import containers.AbstractList;

public abstract class BookList<Element> extends AbstractList<Object> {
public int size () {
return this.size();
}

}[/CODE]

And this is inside ListEngine.java
Code:
		ListEngine engine = new ListEngine();
		BookList blist = new BookList<ListEngine>();

My problem is coming from:
Code:
BookList blist = new BookList<ListEngine>();

Here is what Eclipse is telling me:
Multiple markers at this line
- BookList is a raw type. References to generic type BookList<Element>
should be parameterized
- Line breakpoint:ListEngine [line: 181] - main(String[])
- Cannot instantiate the type BookList<ListEngine>

Thanks for any help provided! :)
 

therevolution

macrumors 6502
May 12, 2003
468
0
If a class is declared 'abstract', as you did for BookList, that means you can't create an object of that type. By declaring something abstract, you're saying "This is not meant to be instantiated directly; rather you should extend this first and use that instead."

For example, think of an abstract class called Shape, which has a method (which should be abstract as well) called getArea(). Depending on the actual shape you care about, like a Circle or Rectangle for example, you'd need to implement getArea() differently, right? Calling Shape.getArea() directly would make no sense because a Shape is an abstract idea. You need a concrete implementation for it to make sense.

In your case, I am guessing that you don't actually want to make BookList abstract. Also, the error:

- BookList is a raw type. References to generic type BookList<Element> should be parameterized

probably means you need to make the line read like this:
Code:
BookList<ListEngine> blist = new BookList<ListEngine>();
 

aLoC

macrumors 6502a
Nov 10, 2006
726
0
You probably don't want a class called BookList unless the assignment explicitly tells you to. Just use an ordinary list and parameterize it with your Book class, e.g.

Code:
class Book {
  String title;
  String isbn;
  String author;
  // ...
}

List<Book> catalog = new ArrayList<Book>();
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.