0

I want to include an interface Printable to this class but it is showing an error.

error:Class file collision: A resource exists with a different case:     
'/example01/bin/com/example/test/test.class'.

This is my code

package com.example.test;

import com.example.test.Printable;

class A implements Printable {
    public void a() {
        System.out.println("a method");
    }

    @Override
    public void b() {

    }

}

abstract class B implements Printable {
    public void b() {
        System.out.println("b method");
    }

}

class Call {
    void invoke(Printable p) {// upcasting
        if (p instanceof A) {
            A a = (A) p;// Downcasting
            a.a();
        }
        if (p instanceof B) {
            B b = (B) p;// Downcasting
            b.b();
        }

    }
}// end of Call class

class Test {
    public static void main(String args[]) {
        Printable p = new A();
        Call c = new Call();
        c.invoke(p);
    }
}

This is my Printable interface class code

public interface Printable {

    public void a ();
    public void b();
}

So how can i import the interface Printable to this class any help would be appreciated. Thanks

9
  • 7
    but it is showing an error What error? Commented Aug 8, 2014 at 12:06
  • 2
    but it is showing an error - well ... which error? Commented Aug 8, 2014 at 12:07
  • error:Class file collision: A resource exists with a different case: '/example01/bin/com/example/test/test.class'. Commented Aug 8, 2014 at 12:09
  • 1
    Rebuild it, make sure all your classes/resources don't clash on name etc. Commented Aug 8, 2014 at 12:09
  • 2
    Here is the rule, at most 1 public(package local is also accepted) class per file. File name should match with class name inside file(case sensitive) Commented Aug 8, 2014 at 12:11

1 Answer 1

2

This is my approach to embed a interface to a class:

public class NestedClassInterface {

/**
 * Nested interface
 * @author Markus
 */
public interface Printable {
    public void a();
}

/**
 * MAIN
 * @param args
 */
public static void main(String[] args) {
    Printable t = new MyTest();
    t.a();
}

/**
 * Static class (otherwise the compiler cannot find it)
 * @author Markus
 *
 */
public static class MyTest
implements Printable {
    public void a() {
        System.out.println("NestedClassInterface.MyTest.a()");
    }
}

}

Notes

Keep us posted on your progress.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.