小编Dav*_*ica的帖子

Java抛出的抽象类

如果我有一个具有以下功能的抽象类 -

abstract class A{
    void foo(String s) throws Exception{
        throw new Exception("exception!");
    }
}
Run Code Online (Sandbox Code Playgroud)

然后是另一个扩展抽象类并实现其自己的foo版本的类 -

class B extends A{
    void foo(String s){
        //do stuff that does *not* throw an exception
    }
}
Run Code Online (Sandbox Code Playgroud)

这会产生问题吗?具体在以下测试案例中 -

Collection<A> col = new Collection<A>();
B b = new B();
col.add(b);
for(A a : col){
    a.foo();
}
Run Code Online (Sandbox Code Playgroud)

我做了一些测试,似乎没有什么破坏,但我不明白为什么B的foo被调用而不是A的

java exception abstract throw

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

没有定义的构造函数

我是.Net的新手,我刚看到这段代码对我来说没有意义(略有删节):

namespace test
{
    public class sub : super
    {
        public sub(string text);
    }
}
Run Code Online (Sandbox Code Playgroud)

如您所见,有一个构造函数接受一个参数,但没有实现定义.这是如何运作的?我的猜测是它以某种方式与超类相关,但我不明白如何,而且我还没能在Google上找到任何东西.

编辑:我在VS2010中运行它,我只是注意到选项卡[from metadata]在标题中.也许这就是为什么?

.net c# constructor

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

传入空集会引发错误

HashSet我正在尝试按照答案在我的 powershell 脚本中使用 a 。

Add-Type -AssemblyName System.Core
$set= new-object 'System.Collections.Generic.HashSet[string]'
Run Code Online (Sandbox Code Playgroud)

但是如果我创建一个需要这样一个集合的函数

function foo([Parameter(Mandatory=$true)][Collections.Generic.HashSet[string]]$set){
Run Code Online (Sandbox Code Playgroud)

并传入集合

foo($set)
Run Code Online (Sandbox Code Playgroud)

如果为空,我会收到错误$set

Cannot bind argument to parameter '$set' because it is an empty collection.
    + CategoryInfo          : InvalidData: (:) [script.ps1], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyCollectionNotAllowed,script.ps1
Run Code Online (Sandbox Code Playgroud)

但如果我事先添加一些东西,$set我就不会遇到问题。

为什么参数不能绑定到空集,如何让它绑定到这样的集?

powershell set hashset powershell-4.0

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

如何在没有两次打电话的情况下获得昨天?

我可以moment通过电话获取昨天的对象

var yesterday = moment().day(moment.day()-1);
Run Code Online (Sandbox Code Playgroud)

但是这需要我打moment两次电话,这让我很烦.有没有办法moment只使用一次API 来实现同样的目的?

javascript days dayofweek momentjs

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

为什么我的 build.sbt 寻找 2.11 版的 hadoop-streaming?

我在 Apache Spark 上做一个复数课程,有一次他们要求我们设置对 Hadoop 流的依赖。我已将其添加到我的build.sbt文件中,但得到的结果出乎意料:

生成.sbt

name := "SparkPlayground"

version := "1.0"

scalaVersion := "2.11.8"

libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.0" % "provided"
libraryDependencies += "com.github.scala-incubator.io" %% "scala-io-core" % "0.4.3"
libraryDependencies += "com.github.scala-incubator.io" %% "scala-io-file" % "0.4.3"
libraryDependencies += "org.apache.hadoop" %% "hadoop-streaming" % "2.7.0"
Run Code Online (Sandbox Code Playgroud)

错误信息

SBT 'SparkPlayground' project refresh failed
    Error:Error:Error while importing SBT project:<br/>...<br/><pre>[info] Resolving org.scala-sbt#task-system;0.13.8 ...

[info] Resolving org.scala-sbt#tasks;0.13.8 ...

[info] Resolving org.scala-sbt#tracking;0.13.8 ...

[info] Resolving org.scala-sbt#cache;0.13.8 ...

[info] Resolving org.scala-sbt#testing;0.13.8 ...

[info] Resolving …
Run Code Online (Sandbox Code Playgroud)

hadoop scala sbt apache-spark

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

如何在Junit5中替换DropwizardAppRule

在Junit 4我可以做类似的事情

@ClassRule
public DropwizardAppRule<Configuration> app = new DropwizardAppRule<>(MyApp.class);

...

app.getLocalPort()
Run Code Online (Sandbox Code Playgroud)

如何在Junit 5中复制此行为?从这个 github问题看起来我需要使用@ExtendWith(DropwizardExtensionsSupport.class),但它不清楚如何

java dropwizard junit-rule junit5

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

部分特化不特化任何模板参数

我有以下代码,其中我试图制作模板化的安全数组迭代器。

template <typename T>
class SArrayIterator;

template <typename E>
class SArray;

class SArrayIteratorException;

template <typename T>
class SArrayIterator<T> {//<--line 16
        friend std::ostream &operator <<(std::ostream &os, const SArrayIterator<T> &iter);
public:
        SArrayIterator<T>(SArray<T> &sArr) : beyondLast(sArr.length()+1), current(0), sArr(sArr){}

        T &operator *(){
                if (current == beyondLast) throw SArrayIteratorException("Attempt to dereference 'beyondLast' iterator");
                return sArr[current];
        }   

        SArrayIterator<T> operator ++(){
                if (current == beyondLast) throw SArrayIteratorException("Attempt to increment 'beyondLast' iterator");
                current++;
                return *this;
        }   

        bool operator ==(const SArrayIterator<T> &other) {return sArr[current] == other.sArr[current];} 
        bool operator !=(const …
Run Code Online (Sandbox Code Playgroud)

c++ templates partial-specialization

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

将select的默认值设置为null选项

根据Angular文档,您可以创建一个不属于模型的null选项.这允许您有一个描述性选项.IE在他们的例子中有-- choose color --.如何将null选项设为默认选项?我希望用户在首次加载页面时看到此描述性空选项.

如果您还可以告诉我如何通过角度禁用null选项,则可以获得奖励积分.

select default angularjs angularjs-select2

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

Angular JS"Controller as"语法不起作用

我之前已经构建了一个AngularJS项目并且熟悉语法.这次我ng-controller="UniversalCtrl as universal"不能工作,我已经尝试了一切.如果我采取universal.showHeader == true并改变它是showHeader == true有效的,但我需要它作为变量universal.就像我说的,我有其他项目遵循相同的结构,他们工作正常.

这是我的HTML代码:

<!DOCTYPE html>
<html>
    <head lang="en">
       <meta http-equiv="cache-control" content="no-store" />
       <meta http-equiv="expires" content="0" />
       <meta http-equiv="X-UA-Compatible" content="IE=edge" />
       <meta http-equiv="pragma" content="no-store" />
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
       <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">

       <link href="styles/MarkStrap.css" rel="stylesheet" />
       <link href="styles/Site.css" rel="stylesheet" />

        <script type="text/javascript" src="js/Angular/angular.min.js"></script>
        <script type="text/javascript" src="js/Angular/angular-route.min.js"></script>
        <script type="text/javascript" src="js/Universal/Universal.js"></script>
        <script type="text/javascript" src="js/Universal/Filters.js"></script>
        <script type="text/javascript" src="js/Universal/Directives.js"></script>

        <title>WIN</title>
        <link rel="shortcut icon" href="winIcon.ico">
    </head>
    <body ng-app="winApp" ng-controller="UniversalCtrl as …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-scope angularjs-controller

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

为什么 TARGETDIR 目录需要名称?

在wix项目中你通常会看到这样的一行

<Directory Id="TARGETDIR" name="SourceDir">
Run Code Online (Sandbox Code Playgroud)

但为什么需要name设置在这里呢?据我了解,该name属性指定执行安装的计算机上生成的文件夹的名称。但是不会创建 SourceDir 文件夹,那么为什么需要它呢?

windows-installer wix

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