草庐IT

input-type-file

全部标签

java - 工厂模式 : Validating input when creating a bean (Guice/Guava)

我正在编写一个新应用,使用Guice进行依赖注入(inject),并使用Guava的先决条件进行属性验证。我正在使用工厂模式根据外部输入创建bean。问题是,验证输入的首选方式是什么?(在可维护性、清晰度等方面)让我们假设这些类:Bean.javapublicinterfaceBean{publicObjectgetFoo();}BeanImpl.javapublicclassBeanImplimplementsBean{privatefinalObjectfoo;publicBeanImpl(Objectparam){foo=param;}@OverridepublicStringg

java - JBoss EAP 6.1 错误 : This runtime type requires a JDK. 此服务器执行环境的当前默认 VM 未被识别为 JDK

你可以检查这个警告here当我添加服务器时,我会这样。请帮帮我。谢谢 最佳答案 转到窗口->首选项->java->安装的jres点击“添加”,添加JDK路径。 关于java-JBossEAP6.1错误:ThisruntimetyperequiresaJDK.此服务器执行环境的当前默认VM未被识别为JDK,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/33907249/

java - Apache 事务 :write file transactionally - how to use resourceId

如果有人实现了事务写入文件,请帮助我。相关主题已在较早的线程(transactionalwrite)中讨论过。用例如下:如果写入日志文件失败,应回滚相应的数据库事务。因此写入文件应该以事务方式执行。我选择了ApacheCommonsTransaction库。有问题,这不会让我更进一步,因为没有找到合适的文档或示例。我已经创建了FileResourceManager实例:FileResourceManagerfrm=newFileResourceManager("c:\cur","c:\cur",true,logger);据我了解ApacheCommonsTransactiontutor

java - 是否有 Class.isAssignableFrom 与 Type 对象一起使用的替代方法?

在Java中,Class有一个isAssignableFrommethod定义如下:publicbooleanisAssignableFrom(Classcls)DeterminesiftheclassorinterfacerepresentedbythisClassobjectiseitherthesameas,orisasuperclassorsuperinterfaceof,theclassorinterfacerepresentedbythespecifiedClassparameter.Itreturnstrueifso;otherwiseitreturnsfalse.Ift

java - 在运行时设置 java.util.logging.config.file

我试图在运行时设置javautil日志记录配置文件,以避免必须将其设置为VM参数。但这行不通。每当我尝试重新读取配置时,日志记录都被禁用。请看下面的代码片段:packagetest;importjava.io.FileInputStream;importjava.util.logging.Level;importjava.util.logging.LogManager;importjava.util.logging.Logger;publicclassA{privatestaticfinalLoggerLOGGER=Logger.getLogger(A.class.getName())

java - 如何重构 "stringly-typed"代码?

我目前正在开发一个代码库,其中有几类变量,例如数据库路径,它们简单地表示为字符串。这些(非)类型的大部分操作都在实用程序类中定义。我创建了一个新类来表示一个数据库,其中的操作定义为传统OOP风格的实例方法。然而,遍历大型代码库并重构它以使用新类型是非常费力的。有没有人对如何快速有效地执行此操作有任何建议? 最佳答案 迁移实用程序类以使用您的新类。那么实用类方法应该只包含两个语句。一个用于创建您的类(class),另一个用于调用您的类(class)。之后,您可以内联实用程序类方法,从而消除对它的需要。完成后,您需要寻找一种方法来避免一

java - 为什么在静态上下文中使用实例方法时 javac 会发出 "error: method in class cannot be applied to given types"?

考虑以下(无效的)Java程序:publicclassTest{publicstaticvoidmain(String[]args){int[]ints={1,2,3,4,5};print(ints);}publicvoidprint(int...ints){for(inti:ints){System.out.print(i);}}}我希望出现与此类似的错误:Cannotmakeastaticreferencetothenon-staticmethodprint(int[])fromthetypeTestatTest.main(Test.java:5)相反,javac发出:Test.j

Git commit 提交时报错: “subject may not be empty“ 或 “type may not be empty“

Gitcommit提交时报错,提示信息如下:⧗input:项目搭建:基于xx框架搭建的...,包含一些基础示例和项目配置✖subjectmaynotbeempty[subject-empty]✖typemaynotbeempty[type-empty]✖found2problems,0warningsⓘGethelp:https://github.com/conventional-changelog/commitlint/#what-is-commitlinthusky-commit-msghookexitedwithcode1(error)报错原因使用Git提交代码时,commitmessa

java - 为什么 dir.mkdir() 不需要异常处理,而 file.createNewFile() 需要?

这是一个代码片段。Filedir=newFile("dir");dir.mkdir();Filefile=newFile(dir,"file.txt");try{file.createNewFile();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}我想知道为什么在dir.mkdir()时不需要异常处理,而在file.createNewFile()时需要异常处理。我们是否非常确定创建目录时“不会出错”?若有,原因为何? 最佳答案 好问题

java - 如何使用@Target(ElementType.TYPE_USE) 处理注解?

我正在实现一个注释处理器,以确保标有注释的元素是实现特定接口(interface)的类的实例,或者是实现特定接口(interface)的类型的使用:@Documented@Target(value={ElementType.PARAMETER,ElementType.TYPE_USE})@Retention(value=RetentionPolicy.RUNTIME)public@interfaceAuditSubject{}publicinterfaceAuditable{//methodsthatprovidedataforwritingalogentry...}publiccla