#import failed: "package does not exist"

1 messages · Page 1 of 1 (latest)

misty hollow
#

Hi. I have the following scripts in the same folder:

Statements.java

public class Statements {
    public static class Equal<T1,T2> {
        T1 a;
        T2 b;

        public Equal(T1 a, T2 b){
            this.a = a;
            this.b = b;
        }
    }
}

Axioms.java

import Statements.Equal;

public class Axioms {
    public static <T> Equal<T,T> EqRefl(T a) {
        return new Equal<T,T>(a,a);
    }

    public static <T1,T2> Equal<T1,T2> EqComm(Equal<T1,T2> eq) {
        return new Equal<T2,T1>(eq.b,eq.a);
    }

    public static <T1,T2,T3> Equal<T1,T3> EqTrans(Equal<T1,T2> eq1, Equal<T2,T3> eq2) {
        if (eq1.b != eq2.a) {
            throw new RuntimeException("second operand of first equality must be first operand of second equality");
        }
        return new Equal<T1,T3>(eq1.a,eq2.b);
    }
}

When I try to compile the latter with javac Axioms.java, I get the error Axioms.java:1: error: package Statements does not exist

tired badgeBOT
#

<@&987246399047479336> please have a look, thanks.

undone egret
#

And to answer your question, you need to give to java the list of all the files you want to compile

#

so javac Axioms.java Statements.java or simply javac *.java

#

import Statements.Equal;
Also, this needs to be import static Statements.Equal;

misty hollow
undone egret
misty hollow
undone egret
misty hollow
#

yes

undone egret
#

ah

misty hollow
#

the latter, specifically (not that it matters)

undone egret
#

you probably need to put them in a package

misty hollow
#

I put package proofs; (proofs being the name of the folder they're in) at the top of both files

#

The error message does not seem to have changed

undone egret
#

import static proofs.Statements.Equal; ?

misty hollow
#

...oh! obviously...

#

YIKES okay good thing I finally installed the Java extension

undone egret
#

Also

#

why do you create a class to put a class ?

misty hollow
#

It's going to have more classes in the future

undone egret
#

why do you not use a package instead ?

misty hollow
#

hm

undone egret
#

delete statements class

#

and use a package instead

misty hollow
#

I do like the fact Equal is of type Statement here though. I guess I should be putting them in separate files, shouldn't I?

undone egret
#

it's a class within Statements class

#

should be a package

#

Also you can use record Equal<T1, T2>(T1 a, T2 b) {} instead of what you have

#

@misty hollow

misty hollow
#

What's record?

undone egret
#

a new kind of class

#

an immutable class where you declare the fields in the class declaration itself

#

constructors, getters, equals, hashcode, toString are automatically generated

#

and you can pattern match on it

#

@misty hollow

misty hollow
#

I managed to get everything to compile properly

#

As for everything else, I'll work on it later