How to find module of Integer(Generic) in Java
up vote
0
down vote
favorite
I have Dual LinkedList
(DLL
) that I wanna separate in two DLL
s, one with only odd numbers and the other with even. But I'm getting error when I try to ((Generic)%2==0)
Error Message: The method parseInt(E)
is undefined for the type DLL<E>
public DLL parni() {
DLL<E>niza = new DLL<E>();
DLLNode<E>tmp = first;
while(tmp.succ != null) {
if((parseInt(tmp.element)) % 2 != 0) {
niza.insertLast(tmp.element);
delete(tmp);
}
tmp = tmp.succ;
}
}
tmp.element is generic of type E
By the way, I tried adding the super class Number in the DLL
class
class DLL<E extends Number>
Any advices?
java generics linked-list
add a comment |
up vote
0
down vote
favorite
I have Dual LinkedList
(DLL
) that I wanna separate in two DLL
s, one with only odd numbers and the other with even. But I'm getting error when I try to ((Generic)%2==0)
Error Message: The method parseInt(E)
is undefined for the type DLL<E>
public DLL parni() {
DLL<E>niza = new DLL<E>();
DLLNode<E>tmp = first;
while(tmp.succ != null) {
if((parseInt(tmp.element)) % 2 != 0) {
niza.insertLast(tmp.element);
delete(tmp);
}
tmp = tmp.succ;
}
}
tmp.element is generic of type E
By the way, I tried adding the super class Number in the DLL
class
class DLL<E extends Number>
Any advices?
java generics linked-list
You should use tmp.element.intValue() instead.
– victini
Nov 19 at 12:01
What's wrong with it? It compiles (I addedfirst
and a return value to the method)
– Michael
Nov 19 at 12:02
@victini thanks man it worked
– borceste
Nov 19 at 13:55
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have Dual LinkedList
(DLL
) that I wanna separate in two DLL
s, one with only odd numbers and the other with even. But I'm getting error when I try to ((Generic)%2==0)
Error Message: The method parseInt(E)
is undefined for the type DLL<E>
public DLL parni() {
DLL<E>niza = new DLL<E>();
DLLNode<E>tmp = first;
while(tmp.succ != null) {
if((parseInt(tmp.element)) % 2 != 0) {
niza.insertLast(tmp.element);
delete(tmp);
}
tmp = tmp.succ;
}
}
tmp.element is generic of type E
By the way, I tried adding the super class Number in the DLL
class
class DLL<E extends Number>
Any advices?
java generics linked-list
I have Dual LinkedList
(DLL
) that I wanna separate in two DLL
s, one with only odd numbers and the other with even. But I'm getting error when I try to ((Generic)%2==0)
Error Message: The method parseInt(E)
is undefined for the type DLL<E>
public DLL parni() {
DLL<E>niza = new DLL<E>();
DLLNode<E>tmp = first;
while(tmp.succ != null) {
if((parseInt(tmp.element)) % 2 != 0) {
niza.insertLast(tmp.element);
delete(tmp);
}
tmp = tmp.succ;
}
}
tmp.element is generic of type E
By the way, I tried adding the super class Number in the DLL
class
class DLL<E extends Number>
Any advices?
java generics linked-list
java generics linked-list
edited Nov 19 at 12:08
deHaar
2,13831326
2,13831326
asked Nov 19 at 11:56
borceste
82
82
You should use tmp.element.intValue() instead.
– victini
Nov 19 at 12:01
What's wrong with it? It compiles (I addedfirst
and a return value to the method)
– Michael
Nov 19 at 12:02
@victini thanks man it worked
– borceste
Nov 19 at 13:55
add a comment |
You should use tmp.element.intValue() instead.
– victini
Nov 19 at 12:01
What's wrong with it? It compiles (I addedfirst
and a return value to the method)
– Michael
Nov 19 at 12:02
@victini thanks man it worked
– borceste
Nov 19 at 13:55
You should use tmp.element.intValue() instead.
– victini
Nov 19 at 12:01
You should use tmp.element.intValue() instead.
– victini
Nov 19 at 12:01
What's wrong with it? It compiles (I added
first
and a return value to the method)– Michael
Nov 19 at 12:02
What's wrong with it? It compiles (I added
first
and a return value to the method)– Michael
Nov 19 at 12:02
@victini thanks man it worked
– borceste
Nov 19 at 13:55
@victini thanks man it worked
– borceste
Nov 19 at 13:55
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
If E extends java.lang.Number, you can try like this:
if(tmp.element.intValue() % 2 != 0)
add a comment |
up vote
1
down vote
Simple: you wrote your own class DLL<E extends Number>
.
Now you wrote code that intends to call a method parseInt()
belonging to your own class DLL.
The compiler is telling you:
The method parseInt(E) is undefined for the type DLL
that you didn't write that method yet.
In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E
generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.
Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.
For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
– Michael
Nov 19 at 12:05
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
If E extends java.lang.Number, you can try like this:
if(tmp.element.intValue() % 2 != 0)
add a comment |
up vote
0
down vote
accepted
If E extends java.lang.Number, you can try like this:
if(tmp.element.intValue() % 2 != 0)
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
If E extends java.lang.Number, you can try like this:
if(tmp.element.intValue() % 2 != 0)
If E extends java.lang.Number, you can try like this:
if(tmp.element.intValue() % 2 != 0)
answered Nov 19 at 12:08
victini
1146
1146
add a comment |
add a comment |
up vote
1
down vote
Simple: you wrote your own class DLL<E extends Number>
.
Now you wrote code that intends to call a method parseInt()
belonging to your own class DLL.
The compiler is telling you:
The method parseInt(E) is undefined for the type DLL
that you didn't write that method yet.
In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E
generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.
Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.
For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
– Michael
Nov 19 at 12:05
add a comment |
up vote
1
down vote
Simple: you wrote your own class DLL<E extends Number>
.
Now you wrote code that intends to call a method parseInt()
belonging to your own class DLL.
The compiler is telling you:
The method parseInt(E) is undefined for the type DLL
that you didn't write that method yet.
In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E
generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.
Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.
For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
– Michael
Nov 19 at 12:05
add a comment |
up vote
1
down vote
up vote
1
down vote
Simple: you wrote your own class DLL<E extends Number>
.
Now you wrote code that intends to call a method parseInt()
belonging to your own class DLL.
The compiler is telling you:
The method parseInt(E) is undefined for the type DLL
that you didn't write that method yet.
In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E
generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.
Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.
Simple: you wrote your own class DLL<E extends Number>
.
Now you wrote code that intends to call a method parseInt()
belonging to your own class DLL.
The compiler is telling you:
The method parseInt(E) is undefined for the type DLL
that you didn't write that method yet.
In other words: if you intend to have a method with that name on your own class, then you have to add such a method to your class. So far, that E
generic parameter isn't of any significance. Like any other method you intend to call on an object, that method must exist on the corresponding class.
Beyond that: do not use names such as "DLL". Don't abbreviate class names. Their names communicate to human readers, and DLL communicates nothing. Call it DualLinkedList for example.
answered Nov 19 at 11:59
GhostCat
86.5k1684143
86.5k1684143
For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
– Michael
Nov 19 at 12:05
add a comment |
For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
– Michael
Nov 19 at 12:05
For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
– Michael
Nov 19 at 12:05
For a second I thought you were wrong about the name 'DLL'. After reading OP's question I thought it was representing a dynamic-link library (and the URL class is not named UniformResourceLocator, after all). So yeah, that demonstrates perfectly how misleading the name is in this instance.
– Michael
Nov 19 at 12:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374134%2fhow-to-find-module-of-integergeneric-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You should use tmp.element.intValue() instead.
– victini
Nov 19 at 12:01
What's wrong with it? It compiles (I added
first
and a return value to the method)– Michael
Nov 19 at 12:02
@victini thanks man it worked
– borceste
Nov 19 at 13:55