[5683] in java-interest

home help back first fref pref prev next nref lref last post

Re: Compiling enum interface

daemon@ATHENA.MIT.EDU (Greg Ewing)
Thu Feb 22 09:21:43 1996

Date: Thu, 22 Feb 1996 15:32:59 +1100
From: grege@optimation.com.au (Greg Ewing)
To: java-interest@java.sun.com
Cc: pc1@doc.ic.ac.uk

> From NewsGroup_comp-lang-java Thu Feb 22 08:22 EST 1996
> From: NewsGroup_comp-lang-java
> >From: "P. Carlier" <pc1@doc.ic.ac.uk>
> Subject: Compiling enum interface
> Date: 20 Feb 1996 18:47:32 GMT
> Nntp-Posting-Host: oak50.doc.ic.ac.uk
> Mime-Version: 1.0
> Content-Transfer-Encoding: 7bit
> X-Url: news:comp.lang.java/10980-11079?ALL
> 
> I suppose the answer is easy (or the question stupid) but I don't understand.
> 
> I have used an interface to define an enum type:
> 
> public interface oid_type {
> public static final int dom_t = 1;    
> public static final int obj_t = 2;
> }
> 
> I have implemented it in:
> 
> public class oid implements oid_type {
> 	oid_type oid_t;
> 	String addr;
> 
>  public oid(oid_type oid_t) {
> this.oid_t = oid_t;
> addr = new String("adresse de l'oid"); 
> }
> 
> .. }
> 
> and both compile but it fails when I compile the main :
> 
> ..
> oid objId;
> 
> objId = new oid(oid_type.dom_t);
> 
> and the error message is :
> Main.java:8: No constructor matching oid(int) found in class oid.
> objId = new oid(oid_type.dom_t);
>         ^
> 
> Can anybody helps me ?
> 
> Thank you
> 
> Pierre Carlier
> 

Pierre,

Do you realise that you are passing `oid_type.dom_t' into the constructor?
This is an int. 
Try passing `oid_type' instead. You can then query it using `oid_type.dom_t'.

However since you have made `dom_t' and `obj_t' static, you can access them 
directly from within class `oid' (without passing them into the constructor) 
by using the call `Oid_type.dom_t' or `Oid_type.oid_t'.
Otherwise keep these variables non-static to do what you are after.
BTW your interface name should be capitalised (e.g. Oid_type not oid_type). 

GREG
grege@optimation.com.au

-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post