Home Features Docs Blog Support GitHub

Java code generated with static method using "this"

(social) #1

Hi All

I am using https://material.io/develop/ios/components/snackbars/api-docs/Classes/MDCSnackbarManager.html in my project. The java code generated for this has static method as follows.

    	public static native void setDelegate_unsafe(
    			@Mapped(ObjCObjectMapper.class) MDCSnackbarManagerDelegate value);

	public static void setDelegate(
			@Mapped(ObjCObjectMapper.class) MDCSnackbarManagerDelegate value) {
		Object __old = delegate();
		if (value != null) {
			org.moe.natj.objc.ObjCRuntime.associateObjCObject(this, value);
		if (__old != null) {
			org.moe.natj.objc.ObjCRuntime.dissociateObjCObject(this, __old);

This static method makes use of “this”, which cannot be used in static context.

The ObjC definition is as follows.

@implementation MDCSnackbarManager

    + (void)setDelegate:(id<MDCSnackbarManagerDelegate>)delegate {
      MDCSnackbarManagerInternal *manager = [MDCSnackbarManagerInternal sharedInstance];
      manager.delegate = delegate;


Is this a bug ?

To overcome this I have created an instance variable of type MDCSnackbarManager as follows

private static final MDCSnackbarManager _this = MDCSnackbarManager.alloc().init();

and I am using this “_this” in place of generated “this”.

Just wanted inputs the work around is fine.

On version 1.4.2