小编Man*_*wam的帖子

接口类java中的静态工厂方法

我正在阅读有效的java教科书.第一项是关于使用静态工厂方法而不是公共构造函数.我怀疑的是,如果我指定一个Interface如何指定静态工厂方法Interface?因为java里面不支持静态方法interface.教科书指定了如何创建包含公共静态工厂方法的不可实例化的类.但是这些方法如何访问实现类的私有构造函数呢?

教科书说,如果要定义Interface Type,则创建一个不可实例化的类,Types并在该类中包含静态工厂方法.但是,如何在Types类中定义的方法访问具体实现的私有构造函数Interface Type

编辑: - 下面的句子引用了教科书.请解释一下它的含义

"接口不能有静态方法,因此按照惯例,名为Type的接口的静态工厂方法放在名为Types的不可实例化的类(Item 4)中"

编辑: - 取自Effective Java作者:Joshua Bloch:第1项 - 静态工厂方法

     public interface Foo{ //interface without plural 's' (question 1)
     public void bar();
 }
 public abstract class Foos(){ // abstract factory with plural 's' (question 1)
    public static Foo createFoo(){
        return new MyFoo();
    }
    private class MyFoo implements Foo{ // a non visible …
Run Code Online (Sandbox Code Playgroud)

java static-factory

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

如何在 React Native 和 android 中创建本地通知

我正在尝试使用 react-native 在 android 中创建本地通知。我的应用程序完全是本地的,所以我不想使用 GCM 或 FCM。我看到了这个问题

它是使用 java 完成的。react native 中是否有包装器或库来实现相同的功能?

我也看到了PushNotificationIOSAPI,它可以与 android 一起使用吗?

notifications android react-native

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

从GitHub导入maven原型

我想开始一个新的Drop-Wizard项目.在DW github(这里)中指定了maven原型.但我不知道如何将它导入我的Intellij Idea的添加Archtype选项.具体,我必须在存储库字段中提供哪个链接.任何帮助,将不胜感激.

github intellij-idea maven dropwizard maven-archetype

8
推荐指数
1
解决办法
4047
查看次数

dropwizard的不同组ID(io.dropwizard和com.yammer.dropwizard)

为什么dropwizard有两个不同的groupId.
io.dropwizard
com.yammer.dropwizard

当你在git pom文件中看到.它有io.dropwizard https://github.com/dropwizard/dropwizard/blob/master/pom.xml

但在其网站上,建议使用com.yammer.dropwizard.
http://www.dropwizard.io/getting-started/

我很迷惑.请帮忙.

maven dropwizard

6
推荐指数
1
解决办法
1749
查看次数

调用在golang中作为接口变量接收的函数

我有一个类似于以下的代码

package main

import "fmt"

func PrintThis(arg string) {
    fmt.Printf("I'm printing %s", arg)
}

func PrintThisAndThat(arg1, arg2 string) {
    fmt.Printf("Now printing %s and %s", arg1, arg2)
}

func Invoke(fn interface{}, args ...string) {
    //fn(args...)
}

func main() {
    Invoke(PrintThis, "foo")
    Invoke(PrintThisAndThat, "foo", "bar")
}
Run Code Online (Sandbox Code Playgroud)

这不是实际的生产代码,但这是一个简化版本.

问题: - 如果我取消注释该行,//fn(args...)我会收到编译错误prog.go:14: cannot call non-function fn (type interface {})

如何执行Invoke()函数作为参数接收的函数?

实现这一目标的正确方法是什么?

generics reflection interface go

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

程序退出时关闭执行程序服务

我正在使用expiry. 我正在使用 aScheduledThreadExecutor来安排从缓存中删除条目。我的问题是执行程序永远不会关闭。我已经尝试过executor.shutdown()方法,shutdownHook但即使在我的主程序完成执行之后它也没有被执行。我也不喜欢终结器。我的代码如下。我希望在closeCache()主程序退出时执行该方法。

public class TimeCacheManual<K,V> {

private final int maxSize;
private final long timeToLive;
private Map<K, V> keyValueMap;
private Map<K,ScheduledFuture > keySchedulerMap;
private Queue<K> keys;
private final ScheduledExecutorService scheduler;
 /*
* creates new instance of TimeBasedEvictionCache.
* @param maxSize must be greater than zero
* @param timeToLive must be greater than zero
* @throws IllegalArgumentException if {@code maxSize<1||timeToLive<1}
* */
public TimeCacheManual(int maxSize,long timeToLive) {
    if(maxSize<1||timeToLive<1){
        throw new IllegalArgumentException(); …
Run Code Online (Sandbox Code Playgroud)

java executorservice

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