草庐IT

option-type

全部标签

java - 可选地获取字段

我有这样一个类结构:publicclassFoo{privateFooBfoob;publicOptionalgetFoob(){returnOptional.ofNullable(foob);}}publicclassFooB{privateintvalA;publicintgetValA(){returnvalA;}}我的目标是调用fooB的get方法,然后检查它是否存在。如果存在则返回valA属性,如果不存在则返回null。所以像这样:IntegervalA=foo.getFoob().ifPresent(getValA()).orElse(null);当然这不是正确的Java8

java - 为什么我会收到错误 "File cannot be resolved to a type"?

这是我的部分代码try{BufferedReaderin=newBufferedReader(newInputStreamReader(System.in));while((line=in.readLine())!="exit"){System.out.println("Entercommand");line=in.readLine();CommandcurrentCommand=newCommand(line);FilecurrentFile=newFile(currentCommand.getLsPath());currentCommand.getLsPath()方法返回一个字符串

Java Optional 和 orElse

这个问题在这里已经有了答案:Differencebetween`Optional.orElse()`and`Optional.orElseGet()`(9个回答)WhenIneedtouseOptional.orElseGet()overOptional.orElse()(3个答案)关闭3年前。我是Java选项的新手,但我看到这段代码是由另一位开发人员编写的,但我不明白:Stringt=null;Optional.ofNullable("notnull").orElse(Optional.ofNullable(t).orElseThrow(()->newException("MyExc

java - 我如何反对像 Java 这样的强类型语言中的 Duck-typing?

我在一个Java程序员团队工作。我的一位同事不时建议我做一些类似“只添加一个类型字段”(通常是“字符串类型”)的事情。否则代码将被提交满载“if(fooinstanceofFoo){...}elseif(fooinstanceofBar){...}”。尽管乔什·布洛赫(JoshBloch)告诫说“标记类是对适当类层次结构的wan模仿”,但我对这种事情的唯一react是什么?然后我如何更认真地阐述这个概念?我很清楚-上下文是Java-正在考虑的对象类型就在我们集体面前-IOW:紧跟在“类”、“枚举”或“接口(interface)”等之后的词。但是除了难以证明或量化(当场)“它使您的代码更

java - Play Framework : PersistenceException: The type is not a registered entity? (Ebean)

我正在学习适用于Java的PlayFramework2.0教程,但在尝试保存ebean模型(task.save())时遇到此错误。[PersistenceException:Thetype[classmodels.Task]isnotaregisteredentity?Ifyoudon'texplicitlylisttheentityclassestouseEbeanwillsearchforthemintheclasspath.IftheentityisinaJarchecktheebean.search.jarspropertyinebean.propertiesfileorche

java - 注释 "not applicable to type"

多年来我一直是IntelliJ的Eclipse用户,所以我真的发现了这个错误,所有对@Override的注释都显示错误“notapplicabletotype”例如,来自JBossErrai的@PostConstruct注释到处都显示此错误,其中导入完全没有错误。我该如何解决这个问题?更新:例如@PostConstruct//Whenhoveredwiththemousepointer'@PostContruct'isnotapplicabletomethodpublicvoidinit(){}截图:http://snag.gy/q5cW5.jpg 最佳答案

java - 使用 Java ODBC 创建连接会导致 java.sql.SQLException : Invalid Cursor Type exception

我正在尝试创建一个访问ODBC数据源的Java程序。使用以下代码...Connectionconn;try{Driverd=(Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();DriverManager.registerDriver(d);StringURL="jdbc:odbc:ARSystemODBCDataSource";conn=DriverManager.getConnection(URL);}catch(SQLException|InstantiationException|IllegalA

java - X-Frame-Options 支持同一域的不同子域

我想知道是否可以为同一域的不同子域支持X-Frame-Options。 最佳答案 X-Frame-Options有一个ALLOW-FROMuri(老实说,我还没有找到一个有多个uri的好例子)。不幸的是,根据OWASP,它不受那么多浏览器的支持。(虽然这篇文章似乎有点过时了)。建议您使用CSP(内容安全政策) 关于java-X-Frame-Options支持同一域的不同子域,我们在StackOverflow上找到一个类似的问题: https://stackov

实体字段中的 Java 8 可选

这个问题在这里已经有了答案:MappingaFunctionalJavaOptionwithHibernate(3个答案)关闭6年前。我可以在hibernate实体的字段中使用Optional吗?也许有一些自定义用户类型?我知道我可以在使用AccesType.FIELD的方法中使用它(无论如何我都使用AccesType.FIELD)。我为什么要这个?好吧,我想尽可能远离空值。

java - 混合模式下的 jstack : WrongTypeException: No suitable match for type of address

我正在尝试以混合模式在ubuntu上运行jstack:$jstack-m7219结果是这个异常:AttachingtoprocessID7219,pleasewait...Debuggerattachedsuccessfully.Servercompilerdetected.JVMversionis25.162-b12Exceptioninthread"main"java.lang.reflect.InvocationTargetExceptionatsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.refl