Naming:
##Hiding inner classes:
Hiding inner classes:
##Consistency:
Consistency:
##Hiding inner classes:
##Consistency:
Naming:
Hiding inner classes:
Consistency:
Additionally the inner class is static. This prevents access from the inner class to the outer one when using this
. For more information have a look at this CR-Answer. this CR-Answer.
Additionally the inner class is static. This prevents access from the inner class to the outer one when using this
. For more information have a look at this CR-Answer.
Additionally the inner class is static. This prevents access from the inner class to the outer one when using this
. For more information have a look at this CR-Answer.
##Inheriting:
You did create a List
. In Java it's customary to implement Interfaces if you have classes with similar use-cases and methods.
public class list<T> {
This should/could be:
You did create a List
. In Java it's customary to implement Interfaces if you have classes with similar use-cases and methods.
public class list<T> {
This should/could be:
public class List<T> implements java.util.List<T> {
In fact (削除ここまで)
public class List<T> implements java.util.List<T> {
##Naming: In fact I suggest you also change the name of your implementation to avoid confustion. Java already comes with two lists ((iinterface)java.util.List
and (cclass)java.awt.List
), that are just named List, you don't really need to introduce a third one ;)
By the way, if you implement an interface you are required to Override the methods that are specified by it.
In the case of List
that's quite a few, including but not restricted to:
public int size();
public boolean isEmpty();
public boolean contains(T item);
public void add(T item);
public void remove(T item);
When implementing them make sure to use the @Override
annotation:
@Override
public void add(T item) {
Node<T> oldHead = this.head;
this.head = new Node<T>(item);
head.setNext(oldHead);
oldHead.setPrev(head);
size++;
}
Which brings me to my next point:
In the case of List
that's quite a few, including but not restricted to:
public int size();
public boolean isEmpty();
public boolean contains(T item);
public void add(T item);
public void remove(T item);
When implementing them make sure to use the @Override
annotation:
@Override
public void add(T item) {
Node<T> oldHead = this.head;
this.head = new Node<T>(item);
head.setNext(oldHead);
oldHead.setPrev(head);
size++;
}
Which brings me to my next point: (削除ここまで)
While we're at itconstructors / initialization:
##Inheriting:
You did create a List
. In Java it's customary to implement Interfaces if you have classes with similar use-cases and methods.
public class list<T> {
This should/could be:
public class List<T> implements java.util.List<T> {
In fact I suggest you also change the name of your implementation to avoid confustion. Java already comes with two lists ((i)java.util.List
and (c)java.awt.List
), that are just named List, you don't really need to introduce a third one ;)
By the way, if you implement an interface you are required to Override the methods that are specified by it.
In the case of List
that's quite a few, including but not restricted to:
public int size();
public boolean isEmpty();
public boolean contains(T item);
public void add(T item);
public void remove(T item);
When implementing them make sure to use the @Override
annotation:
@Override
public void add(T item) {
Node<T> oldHead = this.head;
this.head = new Node<T>(item);
head.setNext(oldHead);
oldHead.setPrev(head);
size++;
}
Which brings me to my next point:
While we're at it:
(削除) Inheriting:
You did create a List
. In Java it's customary to implement Interfaces if you have classes with similar use-cases and methods.
public class list<T> {
This should/could be:
public class List<T> implements java.util.List<T> {
In fact (削除ここまで)##Naming:
I suggest you change the name of your implementation to avoid confustion. Java already comes with two lists ((interface)java.util.List
and (class)java.awt.List
), that are just named List, you don't really need to introduce a third one ;)
(削除) By the way, if you implement an interface you are required to Override the methods that are specified by it.
In the case of List
that's quite a few, including but not restricted to:
public int size();
public boolean isEmpty();
public boolean contains(T item);
public void add(T item);
public void remove(T item);
When implementing them make sure to use the @Override
annotation:
@Override
public void add(T item) {
Node<T> oldHead = this.head;
this.head = new Node<T>(item);
head.setNext(oldHead);
oldHead.setPrev(head);
size++;
}
Which brings me to my next point: (削除ここまで)
While we're at constructors / initialization: