Swift 中未显示 J2ObjC JavaUtilHashMap

J2ObjC JavaUtilHashMap Not Showing in Swift

我有一个带 HashMap 的 object 元数据(HashMap<String, String> 类型),我在 Swift 应用程序中使用它。

object 的所有其他属性都可以通过 Swift(通过桥接 header)访问,但元数据不能。

在Java中定义这个类型时有什么需要注意的吗? 这是代码:

package com.superpixel.advokit.temple8.domain;

import com.superpixel.advokit.temple8.api.network.ApiCallback;

import java.util.Date;
import java.util.HashMap;

public class User extends ApiResource {

    private String id;
    private boolean isLive;
    private Date created;
    private Date updated;
    private String email;
    private String forename;
    private String surname;

    private HashMap<String, String> metadata;

    // -- API

    public static void get(String id, ApiCallback<User> callback) {
        apiService.get(User.class, "/users/" + id, callback);
    }

    // -- Accessors

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public boolean isLive() {
        return isLive;
    }

    public void setLive(boolean live) {
        isLive = live;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public Date getUpdated() {
        return updated;
    }

    public void setUpdated(Date updated) {
        this.updated = updated;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getForename() {
        return forename;
    }

    public void setForename(String forename) {
        this.forename = forename;
    }

    public String getSurname() {
        return surname;
    }

    public void setSurname(String surname) {
        this.surname = surname;
    }

    public HashMap<String, String> getMetadata() {
        return metadata;
    }

    public void setMetadata(HashMap<String, String> metadata) {
        this.metadata = metadata;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (isLive != user.isLive) return false;
        if (id != null ? !id.equals(user.id) : user.id != null) return false;
        if (created != null ? !created.equals(user.created) : user.created != null) return false;
        if (updated != null ? !updated.equals(user.updated) : user.updated != null) return false;
        if (email != null ? !email.equals(user.email) : user.email != null) return false;
        if (forename != null ? !forename.equals(user.forename) : user.forename != null) return false;
        if (surname != null ? !surname.equals(user.surname) : user.surname != null) return false;
        return metadata != null ? metadata.equals(user.metadata) : user.metadata == null;

    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (isLive ? 1 : 0);
        result = 31 * result + (created != null ? created.hashCode() : 0);
        result = 31 * result + (updated != null ? updated.hashCode() : 0);
        result = 31 * result + (email != null ? email.hashCode() : 0);
        result = 31 * result + (forename != null ? forename.hashCode() : 0);
        result = 31 * result + (surname != null ? surname.hashCode() : 0);
        result = 31 * result + (metadata != null ? metadata.hashCode() : 0);
        return result;
    }

}

我不是 Swift 开发人员,因此没有明确的答案,但 Java 开发人员建议在 [=] 中使用接口而不是实现 class 17=] API (Effective Java, Item 18)。因此,将元数据的类型定义为 java.util.Map 而不是 HashMap 可能会更好。