Sekz Jedi
Sekz Jedi

Reputation: 57

GWT: Call same instance from different classes

I have an interface (CssResource) that 'instantiates' itself by: MyInterface singleton = GWT.create(MyInterface.class).

When i try to use it, let's say in MyClass2, i just call it by: MyInterface myClass = MyInterface.singleton;

Then if i do the same in MyClass3, am i calling the same instance as MyClass1 or just creating a new instance?

If the latter is the case, is there a way to call the same?

Upvotes: 0

Views: 90

Answers (1)

ramon_salla
ramon_salla

Reputation: 1607

Declare your INSTANCE as static and final inside your ClientBundle interface in that way:

public interface MyResources extends ClientBundle {
  public static final MyResources INSTANCE =  GWT.create(MyResources.class);    
  @Source("my.css")
  public CssResource css();
}

Access your instance like MyResources.INSTANCE, it would not be instantiated twice.

https://developers.google.com/web-toolkit/doc/latest/DevGuideClientBundle

Upvotes: 1

Related Questions