草庐IT

utility-method

全部标签

使用 arquillian+omnifaces 运行测试时出现 java.util.ServiceConfigurationError

我收到以下错误"java.util.ServiceConfigurationError:javax.servlet.ServletContainerInitializer:Providerorg.omnifaces.ApplicationInitializernotfound"在运行Arquillian测试时。我已经把我能做的最基本的测试用例放在这里:https://www.dropbox.com/s/kou5v8kqs5g4g4m/test.zip?dl=0 最佳答案 在尝试运行内置war并在Wildfly独立运行后,我设法将问题

java - 是否可以保证 java.util.Collections.shuffle() 背后的算法在未来的 Java 版本中保持不变?

在未来的java版本中,以下程序是否保证生成具有相同内容和顺序的列表?importjava.util.ArrayList;importjava.util.Arrays;importjava.util.Collections;importjava.util.List;importjava.util.Random;publicclassTest{publicstaticvoidmain(String[]args){Listlist=newArrayList(Arrays.asList("A","B","C","D"));Collections.shuffle(list,newRandom(

java - 流接口(interface) : How empty() method returns Iterable?

@FunctionalInterfacepublicinterfaceStreamableextendsIterable,Supplier>我正在探索StreamableInterface,我遇到的第一个方法是empty()具有以下定义的方法。staticStreamableempty(){returnCollections::emptyIterator;}Collections::emptyIterator返回Iterator但是这个方法的返回类型是Streamable.Streamble扩展了Iterable和Supplier而不是Iterator接口(interface)。我不明

java - gwt uibinder ui :with - calling methods with arguments

我正在使用gwtuibinder。我想为一个字段动态设置值。我正在尝试这样的事情字段的值是这样设置的NameValueStore有两个方法publicStringgetValue(Stringkey){returnlocalizedValues.get(key);}publicStringgetValue(){returnnull;}问题是我无法调用getValue(key)。我只能调用no-args方法,这意味着以下是不可能的Name请澄清是否有一种方法可以实现这一点,我可以在其中调用传递给它的参数的方法。 最佳答案 不支持,只能

java - 月份和 java.util.Formatter

在javadocofjava.util.Formatter我阅读:'m'Month,formattedastwodigitswithleadingzerosasnecessary,i.e.01-13.为什么是13? 最佳答案 Javadoc解释了原因..'m''\u006d'Month,formattedastwodigitswithleadingzerosasnecessary,i.e.01-13,where"01"isthefirstmonthoftheyearand("13"isaspecialvaluerequiredtos

java - 断言失败错误 : null on boolean method

我正在测试一个将两个对象作为参数并返回boolean的方法.当我使用和assertTrue或assertFalse在有问题的方法上,我得到以下测试失败:junit.framework.AssertionFailedError:null.我知道我正在传递无效参数并且可能会导致NPE在方法中,但这不是正在发生的事情,而是测试失败了。注意:我正在使用boolean而不是Boolean.示例代码:类:publicclassMyClass{publicbooleanfoo(MyObject1lhs,MyObject2rhs){//doSomething//returnsomething}}测试:

Java 泛型 : method signature for (deep copy of) generic Maps

我有一些Map,它们本身又可能包含Map(任何类型)。我写了一个带有签名的方法:publicstaticHashMapdeepCopyHashMap(HashMaps);但是,我现在想概括此代码以支持一般的Map,但仍会返回与参数类型相同的对象。所以不是:publicstaticHashMapdeepCopyHashMap(HashMaps);publicstaticCheckedMapdeepCopyCheckedMap(CheckedMaps);publicstaticTreeMapdeepCopyTreeMap(TreeMaps);...etc.我想要这样的东西:publicst

java - 将 Clojure 函数作为 java.util.Function 传递

在主题中,我想使用一个将函数作为参数的Java方法,并为其提供一个Clojure函数,无论是匿名函数还是常规函数。任何人都知道如何做到这一点? 最佳答案 java.util.function.Function是一个接口(interface)。您需要实现抽象方法apply(Tt).应该这样做:(defnhello[name](str"Hello,"name"!"))(defnmy-function[](reifyjava.util.function.Function(apply[thisarg](helloarg))));;thend

java - 获取 java.util.date 小时数的最快方法?

从java.util.date对象开始时:关于性能,将小时部分作为integer的最佳方法是什么?我必须迭代几百万个日期,因此性能很重要。通常我会按如下方式获取小时数,但也许有更好的方法?java.util.Datedate;Calendarcalendar=Calendar.getInstance();calendar.setTime(date);inthours=calendar.get(Calendar.HOUR_OF_DAY); 最佳答案 UTC:inthour=(int)(date.getTime()%86400000)/

java - 错误 : Attempted to call method "format" on null context object

Spring-bootv1.4.1Javav1.8Thymeleafv2.1.5。下面这行代码在我看来:它具有我基于S.O.的语法。问题SpringBootThymeleafOrdinalNumbers,产生错误:org.springframework.expression.spel.SpelEvaluationException:EL1011E:(pos11):Methodcall:Attemptedtocallmethodformat(java.time.LocalDate,java.lang.String)onnullcontextobject但是,如果我在没有Thymeleaf