小编Bub*_*tan的帖子

Lambda表达式在运行时失败并带有java.lang.BootstrapMethodError

在一个包(a)中,我有两个功能接口:

package a;

@FunctionalInterface
interface Applicable<A extends Applicable<A>> {

    void apply(A self);
}
Run Code Online (Sandbox Code Playgroud)

-

package a;

@FunctionalInterface
public interface SomeApplicable extends Applicable<SomeApplicable> {
}
Run Code Online (Sandbox Code Playgroud)

apply超级接口中的方法采用selfas,A否则,如果Applicable<A>使用if ,则类型在包外不可见,因此无法实现该方法.

在另一个包(b)中,我有以下Test类:

package b;

import a.SomeApplicable;

public class Test {

    public static void main(String[] args) {

        // implement using an anonymous class
        SomeApplicable a = new SomeApplicable() {
            @Override
            public void apply(SomeApplicable self) {
                System.out.println("a");
            }
        };
        a.apply(a);

        // implement using a …
Run Code Online (Sandbox Code Playgroud)

java generics lambda package-private

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

格式化Elixir中的时间

我是Elixir的新手,尝试将一个Rails API作为学习项目移植到Phoenix.

我有一个Postgres时间字段,我已添加到Ecto方案中:

field :start_time, Ecto.Time
Run Code Online (Sandbox Code Playgroud)

问题:我想输出一个12小时格式化版本的时间,如16:30作为字符串:例如,下午4:30.我一直无法找到一种简单/标准的方法来做到这一点.

这是我最接近解决方案的:

def format_time(time) do
  {:ok, {hours,minutes,y, z}} = Ecto.Time.dump(time)
  {hour, ampm} = Timex.Time.to_12hour_clock(hours)
  "#{hour}:#{minutes}#{ampm}"
end
Run Code Online (Sandbox Code Playgroud)

对于我认为已经具有更简洁和标准的实现的东西来说,这似乎是一个荒谬而荒谬的长代码; 另外它有输出2:0pm而不是下午2:00的问题 - 用尾随零格式化0也是我正在处理的长而复杂的代码片段 - 此时我开始觉得事情正在发生偏离轨道.

建议赞赏!

elixir phoenix-framework

13
推荐指数
3
解决办法
6734
查看次数

有没有办法在 DefaultTabController 中添加监听器?

我一直在尝试在使用时添加监听器DefaultTabController。但是,每次我添加 aTabController以便获取 和 中的当前索引时TabBarTabBarView我都会在它们之间失去同步。

这是我的代码如下:

  @override
  Widget build(BuildContext context) {
    return new DefaultTabController(
      length: subPages.length,
      child: new Scaffold(
        appBar: appBar('homepage'),
        body: new Center(
          child: new NestedScrollView(
            headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
              return <Widget>[
                new SliverAppBar(
                  backgroundColor: Colors.white,
                  title: new TabBar(
                    labelColor: Colors.black,
                    indicatorColor: Colors.black,
                    labelStyle: new TextStyle(fontWeight: FontWeight.bold),
                    tabs: subPages.map((String str) => new Tab(text: str)).toList(),
                  ),
                ),
              ];
            },
            body: new TabBarView(
              children: subPages.map((String str) {
                return new ListView(
                  padding: const …
Run Code Online (Sandbox Code Playgroud)

dart flutter

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

如何首先按值对HashMap进行排序,然后在重复的情况下按键排序?

我有一个与此类似的 HashMap:

 HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
 map.put(3, 2);
 map.put(7, 2);
 map.put(5, 1);
 map.put(10, 4);
Run Code Online (Sandbox Code Playgroud)

我需要先按值排序,然后按键排序,以防多个键共享相同的值。

结果应如下所示:

(5, 1)
(3, 2)
(7, 2)
(10, 4)
Run Code Online (Sandbox Code Playgroud)

请问有什么建议吗?

我首先比较值,仅在出现重复值的情况下才比较键。所以我同时使用键和值,而不仅仅是值。

java dictionary hashmap

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