This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error: no interface expected here

 
Peter Simon
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have two classes which extend interfaces.
One extends Serializable, the other javax.ejb.EntityBean
I do import the right packages.
java.io.Serializable
and
javax.ejb.*
Compiler complains: no interface expected here.
I guess the solution is pretty straightforward, but I don't see what I'm doing wrong.
thanks for setting this straight.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to be a pedant but do you really mean
extends Serializable?
-Barry
 
Volodymyr Shram
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Peter Simon:
Hi,
I have two classes which extend interfaces.
One extends Serializable, the other javax.ejb.EntityBean
I do import the right packages.
java.io.Serializable
and
javax.ejb.*
Compiler complains: no interface expected here.
I guess the solution is pretty straightforward, but I don't see what I'm doing wrong.
thanks for setting this straight.

Yeah, Barry Gaunt is right, you have to use
implement instead of extends interfaces in your case:

or extends inteface for local/remote interface:

and
implement your serializable object:

...
 
Peter Simon
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the replys.
As I thought it was pretty straightforward.
Have to get used interpreting the errormessages I guess.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Volodymyr got in before me ( while I had to go for my books )
You must implement EntityBean.
Damm... I'll just have to learn to type with four fingers...
[ October 25, 2002: Message edited by: Barry Gaunt ]
 
Volodymyr Shram
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gaunt:
Volodymyr got in before me ( while I had to go for my books )

 
Peter Simon
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I think I got it.
Barry is fast, but Volodymyr is even faster.
Thanks for helping me out guys.
 
Peter Simon
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barry and Volodymyr,
Maybe you can help me with this one aswell...
I have to write a method which as an argument receives an object.
The method has to check with instanceOf wether it is an object of a certain type,(in my case CabinPK)and if so check wether a variable of that object is equal to a variable from the class which implements the method equals.
It seems that the object received as an argument has to be casted to CabinPK first before being able to compare variables.
Would you know how to do this?
Here is my code for what it is worth:
public boolean equals(Object obj){
if(obj instanceof CabinPK == true)
{
if (obj.id == this.id){
return true ;
{

}
 
Bill Liteplo
Ranch Hand
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>It seems that the object received as an argument >has to be casted to CabinPK first before being >able to compare variables.
Once you have successfully tested the class of an object with intanceof, you can safely cast it with (classname)varname. Until you do so, the object is only an Object. It will behave as a CabinPK for just that call when you are casting it.
If you want to make multiple calls to something, each require casting, you can use a local variable for help:

For your problem:

Bill
 
Peter Simon
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill,
I managed to write this:
public boolean equals(Object obj){
boolean result = false;
if(!(obj instanceof CabinPK ))
return false;
{
CabinPK pk = (CabinPK)obj;
if(pk.id == this.id)
{
result = true;
}
return result;
}
but yours defenitly is better.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK you have overridden Object.equals(Object), now
you should provide a suitable int hashCode()
method.
 
Peter Simon
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I did Barry
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant that as an assignment for next week
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic