• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Generics: cannot make a static reference to the non-static type

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I'm just really confused right now... the original signature for the method I'm supposed to write :



So silly me trying to show off figured...



Of course this went over like a lead zeppelin, so...



I "think" I have the correct algorithm to reverse the list, I just need to get past this. After googling around I figured that making the method generic would solve most of the problem... LinkedListNode<T> is an inner class of the abstract class LinkedListClass. I could really use some assistance and a good canonical source with examples on generics since this text sucks on the subject. Thanks.

v
 
Victor Thomas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
finally googled around some more... I probably shouldn't do it this way, however I'm almost out of time and need to submit this as is. However, it does works...

Complete code:









If someone has a better solution, please post it! Again, if anyone could suggest a good tutorial on generics, I'd really appreciate it. If no one replies by tomorrow, I'll mark this as resolved. BTW, this is not the way I'd do an implementation of a Linked List ... Thanks in advance.

v
 
Victor Thomas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I think I have something better now, (at least eclipse quit complaining...)


And...

Don't know what I did right, but at least now I can safely submit the code. I really do wish someone could explain to me the why this is 'better' than my original. I will still wait to mark this as resolved.

v
 
Sheriff
Posts: 28397
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you have about 90 lines of code in each of them. I could scroll back and forth and try to identify the differences, but that's awfully difficult and inconvenient. And you never really did say what you didn't like about the first attempt (and by the way, that stat/non-static issue has nothing to do with generics, and vice versa). So I'm sorry, I'm not going to do that.

On the other hand if you explained what you did, somebody might be able to explain why that was a good thing to do.
 
Victor Thomas
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Well, you have about 90 lines of code in each of them...


Sorry for the amount of code contained herein. Like I expressed earlier, I had to add code to an existing project. I would never write this of my own free will...

Paul Clapham wrote:And you never really did say what you didn't like about the first attempt


What I was concerned with was the what I thought was the problem which happened to by the real problem as you surmised: scope

Paul Clapham wrote: (and by the way, that stat/non-static issue has nothing to do with generics, and vice versa).


I was just watching the tube and realized that the issue was that LinkedListNode is an inner class and that's why it worked when I :

So my original mistake was try to instantiate the inner class. Once I finished kicking myself in the butt, I decided that I shouldn't wait until almost the last minute to complete an assignment again.

Paul Clapham wrote:So I'm sorry, I'm not going to do that.


No worries! I sometimes wear myself down and don't see the problem until I let go. I always hope that a better pair of eyes can spot my insanity quicker than me. I just need to manage my time better...Thanks for your help.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your problem isn't with Generics...your problem was trying to reference a non-static inner class from a static method. You always need an instance of the outer class class to make an instance of a non-static inner class. This can be implicitly done within instance methods because of the 'this' reference...but static code has no 'this' reference...hence to construct an instance of a non-static inner class from a static method you'd have to construct a new outer class first and use that to construct the inner class along the lines of:

Outer.Inner innie = new Outer().new Inner();

(where Inner is a non-static inner class inside Outer and both Outer and Inner are visible to the calling code).
reply
    Bookmark Topic Watch Topic
  • New Topic