小编moh*_*945的帖子

我可以在地图中使用通配符,例如Map <Class <?>,?>

我有一个私人实例

private final Map<Class<?>, ?> map;
Run Code Online (Sandbox Code Playgroud)

从语法上讲,这是正确的.我想做的就是这个.

public class User {
}
public class UserSubclass extends User {
}
public class Role {
}

map.put(User.class, new User()); // valid
map.put(User.class, new UserSubclass()); // valid
map.put(Role.class, new Role()); // valid
// But when I do the following I need to get an error
map.put(User.class, new Role(); // invalid, compiler error
Run Code Online (Sandbox Code Playgroud)
  1. 我该如何申报地图?
  2. 如何将HashMap的对象实例化到此Map?

java generics

4
推荐指数
1
解决办法
203
查看次数

Swift引用属性并传递它

如何将属性引用分配给变量并传递给它.类似于函数的东西,我们可以做这样的事情:

class Foo {

    func executeTask() {
        print("executeTask called")
    }

    var name: String = "name1"
}

// get reference to the executeTask method
let x = Foo.executeTask

// later we can call the executeTask method but using the x variable
x(Foo())()
Run Code Online (Sandbox Code Playgroud)

但我们怎样才能为物业做同样的事情.我原以为:

// get reference to the executeTask method
let y = Foo.name

// later we can call name property but using the y variable
y(Foo())()
Run Code Online (Sandbox Code Playgroud)

但是这给出了错误: instance member 'name' cannot be used on type 'Foo'

编辑:伙计们,问题绝不是要访问实例变量的属性以获取其当前值.这是一个微不足道的问题.再看一下这个executeTask例子.在executeTask …

swift

4
推荐指数
2
解决办法
984
查看次数

如何使用Java测试带有lat/lon和radius的区域内的点?

我要编写一个具有以下签名的方法

public class Position {
double longitude;
double latitude;
}

boolean isInsideTheArea(Position center, double radius, Position point);
Run Code Online (Sandbox Code Playgroud)

因此,如果point在其内部area具有center作为其中心和radius英里为单位的半径,则应该返回true,false否则.

java point area latitude-longitude

3
推荐指数
1
解决办法
2159
查看次数

如何计算iOS中浮点后的位数?

如何计算iOS中浮点后的位数?

例如:

  • 3.105应该返回3
  • 3.0应该返回0
  • 2.2应该返回1

更新: 我们还需要添加以下示例.因为我想知道小数部分中的位数.

  • 1e-1应该返回1

floating-point objective-c ios

3
推荐指数
1
解决办法
2319
查看次数

如何使用Java加载图像并将文本写入其中?

我的图像位于我的java项目中的images/image.png.我想写一个方法,其签名如下

byte[] mergeImageAndText(String imageFilePath, String text, Point textPosition);

此方法将加载位于图像imageFilePath和在位置textPosition欲写入的图像(左上)的text,那么我想返回表示与文本新的图像合并一个字节[].

java merge text image bytearray

2
推荐指数
2
解决办法
9948
查看次数

Android-NDK"java.lang.UnsatisfiedLinkError"

我是NDK的新手.

我有一个cpp文件,它具有以下功能

/* This is a trivial JNI example where we use a native method
 * to return a new VM String. See the corresponding Java source
 * file located at:
 *
 *   apps/samples/hello-jni/project/src/com/example/hellojni/HelloJni.java
 */
JNIEXPORT jstring JNICALL
Java_com_some_player_MainActivity_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
{
    return env->NewStringUTF("Hello from JNI!");
}
Run Code Online (Sandbox Code Playgroud)

调用它的Java类

package com.some.player;
public class MainActivity extends Activity {
    public native String stringFromJNI();
    static {
        System.loadLibrary("hello-jni");
    }

     @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       TextView tv = (TextView) findViewById(R.id.textView); …
Run Code Online (Sandbox Code Playgroud)

android android-ndk

2
推荐指数
1
解决办法
3126
查看次数

NSDate与TimeZone偏移量转换为字符串

我有以下代码

let dateFormatter = NSDateFormatter()

dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
dateFormatter.calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)
dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
dateFormatter.timeZone = NSTimeZone(forSecondsFromGMT: 0)

dateFormatter.stringFromDate(NSDate())
Run Code Online (Sandbox Code Playgroud)

它以以下格式生成日期: 2015-08-06T15:44:49 + 0000 但我希望它采用以下格式2015-08-06T15:44:49 + 00:00

如您所见,偏移量需要为b +00:00而不是+0000

nsdateformatter ios swift

2
推荐指数
1
解决办法
622
查看次数