2 Replies - 157 Views - Last Post: 06 June 2014 - 09:23 AM Rate Topic: -----

#1 dubxcity  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 21-March 14

Interface field question

Posted 06 June 2014 - 09:06 AM

Im just learning interfaces and we are writing a program to calculate parking fees. What im stuck on is an instruction in the assignment my class ParkingCharges has a field called dailyHoursParked. Its type is the interface type List and it is instantiated with a LinkedList of Double

I wrote the dailyHoursParked like this
interface List <dailyHoursParked> = new LinkList<double>;


but it keeps giving me an error how should it be written?

Is This A Good Question/Topic? 0
  • +

Replies To: Interface field question

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Interface field question

Posted 06 June 2014 - 09:15 AM

List<Double> dailyHoursParked = new LinkedList<Double>();


You use the interface keyword when you are defining the interface - not when you use it, therefore there would be a

public interface List {
   // method common to all list implementations (arraylist, linkedlist etc)
}


Other than that you tried to give the variable name in the generic type parameter position, you need to first define the variable type. Here it will be a List of Double objects, then give it a name - dailyHoursParked. Then we assign to that variable a concrete implementation - in this case a LinkedList of Double objects.

You also need to use the Double object wrapper as a generic type parameter (capital) rather than the primitive (lower case) version.
Was This Post Helpful? 1
  • +
  • -

#3 dubxcity  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 21-March 14

Re: Interface field question

Posted 06 June 2014 - 09:23 AM

awesome thank you! I just barely started studying interfaces and it is really confusing me at this point but im sure it will sink in
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1