0

I have a little problem.

Class ll:

interface jj{ public class ll implements gg{ public static String j ="C:\\"; //some code here } } 

Class ggg:

interface gg{ public class ggg extends JFrame implements jj{ //bunch of code + a textfield textField = new JTextField(); textField.setBounds(72, 120, 217, 20); textField.setColumns(10); //bunch of code } } 

CLass aaa

public class aaa implements jj, gg { public aaa(){ //File chooser here + editing strin "j" from class "ll" File f = chooser.getSelectedFile(); if(f!=null) { jj.ll.j = f.getPath(); //And printing "j" string to the text field from ggg class gg.ggg.textField.setText(jj.ll.j); } } } 

My problem is, that text field printing doesn't work. I tryed to System.out.println the jj.ll.j string to test if it has something. and yes it has and works how expected.

5
  • 5
    Are you sure you need classes within interfaces? Commented Jul 21, 2010 at 17:00
  • 6
    My advice is to not embed non-interface classes inside an interface. Commented Jul 21, 2010 at 17:01
  • I need to use j string in 3 others classes. it would be much easier if java mades a multi inheritance feature, but we have what we have. Commented Jul 21, 2010 at 17:10
  • 1
    @shevchuk, use inheritance only when there is a object graph with parent-child relationships between classes. You dont need inheritance to access the same object from 3 other classes. Commented Jul 21, 2010 at 17:29
  • is this intentionally being obfuscated beyond all meaning? This is one of the strangest ways of declaring "public constants" I've ever seen. Commented Jul 21, 2010 at 17:40

2 Answers 2

5

I don't get the logic of making a class inside an interface.

If you need the j string in various classes, just declare it as a public static field in some class. Implementing an interface to get a constant is quite old fashioned. If you use Java 1.5+, do a static import.

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

1 Comment

I don't really get how to do a static import. Could you please give an example.
1

I'm a little surprised that the compiler lets you do that--but unless you are just curious, don't do this.

Just find another way.

Added complexity is never worth it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.