Android使用接口回调实现Activity与Fragment通信

接口回调是指一个使用过程,并强调是关于对象功能的使用过程,既然是功能,功能一般就对应着方法体(函数),因此它同样满足与回调函数相似的模型。

  1. 接口的定义
  2. 接口的实现
  3. 调用接口

将(2)的引用(地址)传递给(3),然后(3)调用(2)中的方法,这一过程称为对象功能的接口回调。

- 阅读全文 -

HttpServletResponse返回JSON数据

@WebServlet("/demo")
public class demo extends HttpServlet {
    private static final long serialVersionUID = 1L;
    
    public demo() {
        super();
    }
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json;charset=utf-8");
        PrintWriter writer = response.getWriter();
        writer.write(JSONObject.toJSONString(data()));
    }
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
    
    private HashMap<String, String> data() {
        HashMap<String, String> map = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            map.put("key" + i, String.valueOf(i));
        }
        return map;
    }
}

- 阅读全文 -

Java输出26个字母任意3字母所有组合(包含重复)

/**
 * 输出26个字母任意3字母所有组合(包含重复)
 * @author fluorine.xyz
 */
public class Print {
    public static void main(String[] args) {
        // 两个数组
        String [] one = new String [26];
        String [] two = new String [26];
        String [] three = new String [26];
        for (int i = 0; i < 26; i++) {
            one[i] = String.valueOf((char)(96 + i + 1));
            two[i] = String.valueOf((char)(96 + i + 1));
            three[i] = String.valueOf((char)(96 + i + 1));
        }
        for (int i = 0; i < one.length; i++) {
            for (int j = 0; j < two.length; j++) {
                for (int k = 0; k < three.length; k++) {
                    System.out.print(one[i] + two[j] + three[k] +",");
                }
            }
        }
    }
}

- 阅读全文 -

解决JDK-12没有JRE的方法

- 阅读全文 -

计算两个时间的日、周间隔差

- 阅读全文 -

【JAVA作业】回合制文字对战游戏v1.0

- 阅读全文 -