我想知道是否可以在foreach循环中直接转换对象.
我们有以下两个类,一个扩展另一个:
class Book {};
class ExtendedBook extends Book {};
Run Code Online (Sandbox Code Playgroud)
现在我们有一系列书籍,我想循环,因为它的ExtendedBook搜索我确信所有书籍实际上都是扩展书籍.有没有办法直接施放它们?
Book [] books = bookSearch.getBooks("extendedBooks");
for (Book book: books){
ExtendedBook eBook = (ExtendedBook) book;
....
}
Run Code Online (Sandbox Code Playgroud)
这涉及两个步骤.首先循环阅读书籍,然后在第二步中投射它们.一个人可以一步到位吗?
什么行不通:
// Directly assign it to a different type
for (ExtendedBook book : books){}
// Directly casting the array
ExtendedBooks [] eBooks = (ExtendedBooks []) books;
// Same goes for trying both in one step
for (ExtendedBook book : (ExtendedBook []) books){}
Run Code Online (Sandbox Code Playgroud)
我知道这不是一个真正的痛苦,但保持循环更短将是很好的,也许更可读,因为你保存一个虚拟变量,它只用于铸造而不是实际的行动.
从多个线程调用writeJava FileOutputStream对象是否安全?输出是否会正确序列化?
澄清:
在我的例子中,类记录器包含一个FileOutputStream引用,多个线程可以调用logger write,它格式化输出并调用FileOutputStream写入.
我是否应该同步我的记录器写入方法以保证来自多个线程的消息不会混合?
我正在以编程方式从ldap导出用户.因此我正在从ldap中检索用户.其中一个属性是whenCreated.
我必须转换的一个值是:20090813145607.0Z直接拆分我得到以下格式:yyyyMMddHHmmss+ .0Z.问题是应用程序在CET时区运行,存储的时间是UTC,可能由表示.0Z.它是14:56 UTC和当地的代表16:56.夏季时间似乎是2小时,冬季则是1小时.
我检查了SimpleDateFormat并且有一个占位符用于时区,但它的格式不同.
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
sdf.parse("20090813145607.0Z");
Run Code Online (Sandbox Code Playgroud)
将显示错误的日期,因为它忽略日期时区.
有没有办法直接转换它?
我目前正在研究IBM Websphere Application Server和IBM Websphere Process Server之间的区别?
我知道Process Server就像是App服务器的更高级别的层,但是想知道使用它们的开发是相同还是相似.我一直在使用集成开发人员和App服务器一段时间,并且想知道是否为Process服务器传输了这些技能.
谢谢你的帮助 :)
我已经创建了Axis2 1.6 Webservice Client,我可以创建wsdl2java.但是,当我运行我的程序..它显示这个错误?..
[INFO] Unable to sendViaPost to url[http://10.53.1.187:7782//rest/UVSInterface_Extend]
org.apache.axis2.AxisFault: Transport error: 404 Error: /error/error404.jsp
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:310)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:194)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.huawei.bme.winuvsinterface.UVSInterface_ExtendStub.manualRecharge(UVSInterface_ExtendStub.java:14628)
at access.KitRecharge.main(KitRecharge.java:113)
org.apache.axis2.AxisFault: Transport error: 404 Error: /error/error404.jsp
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:310)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:194)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.huawei.bme.winuvsinterface.UVSInterface_ExtendStub.manualRecharge(UVSInterface_ExtendStub.java:14628)
at access.KitRecharge.main(KitRecharge.java:113)
Run Code Online (Sandbox Code Playgroud) 我会将全局AngularJS与Liferay Portal一起使用.因为,就像AngularJS的设计一样:
为何选择AngularJS?HTML非常适合声明静态文档,但是当我们尝试使用它来声明Web应用程序中的动态视图时,它就会动摇.AngularJS允许您为应用程序扩展HTML词汇表.由此产生的环境非常具有表现力,可读性和快速开发.
我会通过开发Liferay-Theme和Portlets来简单地使用html的声明性语法.
为了这个要求,我创建了新的Liferay-Theme并定制了一点portal_normal.vm:
<!DOCTYPE html>
<#include init />
<html ... ng-app="liferay">
<head>
...
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
<script type="text/javascript" src="${javascript_folder}/my.js" charset="utf-8"></script>
</head>
<body class="${css_class}">
<div ng-controller="LiferayCtrl">
Run Code Online (Sandbox Code Playgroud)
这里my.js:
angular.module('liferay', [])
.controller('LiferayCtrl', function($scope) {
console.log("---==== Init AngularJS ====---");
$scope.Liferay = Liferay;
});
Run Code Online (Sandbox Code Playgroud)
我可以扩展控制器,就像获取Liferay-Site名称一样.
这有什么帮助的?
因此,我可以通过声明式html语法简单地访问Liferay JavaScript值和函数,而无需像AngularJS那样直接调用JavaScript函数.
例如,现在可以通过声明性html代码获取Liferay JavaScript的值和函数,就像这里一样,用于获取Web内容显示中的当前URL:
Liferay current URL: {{Liferay.currentURL}}
Run Code Online (Sandbox Code Playgroud)

但是,我的问题是:
我创建了简单的增量计数器,如下所示.
global.counter = 0;
exports.handler = (event, context, callback) => {
// TODO implement
callback(null, ++global.counter);
};
Run Code Online (Sandbox Code Playgroud)
每当我测试这个函数时,我都会按预期增加值.
这是正确的方法还是我需要在云数据库中存储计数器?
我已经部署了一个带有本地和远程接口的EJB,我可以在部署后查找本地的一个,但是我无法从Java SE客户端使用远程.
EJB代码很简单:
@Local(DemoFacade.class)
@Remote(DemoFacadeRemote.class)
@Stateless
public class DemoFacadeBean implements DemoFacade
<snip>
Run Code Online (Sandbox Code Playgroud)
查找代码也很简单:
Properties env1 = new Properties();
env1.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
env1.put(Context.PROVIDER_URL, "corbaloc:iiop:localhost:2809");
Context initialContext;
initialContext = new InitialContext(env1);
Object ejbHome = initialContext.lookup("cell/nodes/OVLM46008QPZKQ1Node01/servers/server1/ejb/DemoFacadeRemote");
Run Code Online (Sandbox Code Playgroud)
我也尝试了jndi查找的许多变体,但都失败了同样的错误.
Object ejbHome = initialContext.lookup("cell/nodes/OVLM46008QPZKQ1Node01/servers/server1/java:global/WebSphereDemo/WebSphereDemoEJB/DemoFacadeBean!com.test.DemoFacadeRemote");
Run Code Online (Sandbox Code Playgroud)
我添加了以下参数来帮助调试:
-Dcom.ibm.CORBA.Debug=true -Dcom.ibm.CORBA.CommTrace=true -Dcom.ibm.CORBA.Debug.Output=c:/temp/client.log -Dcom.ibm.ejs.ras.lite.traceSpecification=*=all -Djava.endorsed.dirs=C:/data/workspace/WebSphereDemoEJBTest/lib/websphereclient/eee
Run Code Online (Sandbox Code Playgroud)
类路径设置为websphere/lib文件夹的所有jar.
完整的控制台输出是(抱歉输出的长度,其中一些是省略的).真正的错误在最后.谢谢你的任何建议.
************ Start Display Current Environment ************
<snip>
[26/07/2011 15:49:32:122 EST] 00000000 com.ibm.ws.naming.ipbase.NameSpace > lookUpRootContext Entry
bindingName=IIOP_DEFAULT_ROOT
rootBindingData=com.ibm.ws.naming.ipbase.BindingsTableData@fffd6386
[26/07/2011 15:49:32:123 EST] 00000000 com.ibm.ws.naming.ipbase.NameSpace < lookUpRootContext Exit
javax.naming.NameNotFoundException: Root context not found.
[26/07/2011 15:49:32:123 EST] 00000000 com.ibm.ws.naming.jcache.Cache …Run Code Online (Sandbox Code Playgroud) 如何运行简单的查询,如:
select current timestamp from sysibm.sysdummy1
Run Code Online (Sandbox Code Playgroud)
在旧的"Command Center"中,如果只是能够在不创建脚本/项目的情况下运行这样的命令,则使用查询构建器等.但是在更新期间旧的命令中心被新的Data Studio替换.
我正在尝试重现一个在使用我常用的Aqua Data工作室时不会弹出的错误.但是,使用JDBC和/或Data Studio运行该过程会引发异常.
我正在尝试将日期传递给JAX-RS服务。检查其他问题,例如:日期格式映射到JSON Jackson
答案和说明文件表明,有一个杰克逊注释应允许日期格式。
public class SolutionFilter {
@MatrixParam("toDate")
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd", timezone="CET")
private Date toDate;
public void setToDate(Date toDate) {
this.toDate = toDate;
}
}
Run Code Online (Sandbox Code Playgroud)
致电Rest-Service时,我得到了ParseException:
Caused by: java.text.ParseException: Unparseable date: "2016-01-01"
at java.text.DateFormat.parse(DateFormat.java:366)
at org.glassfish.jersey.message.internal.HttpDateFormat.readDate(HttpDateFormat.java:137)
at org.glassfish.jersey.server.internal.inject.ParamConverters$DateProvider$1.fromString(ParamConverters.java:259)
Run Code Online (Sandbox Code Playgroud)
好像注释被忽略了。调试模式设置为EEE, dd MMM yyyy HH:mm:ss zzz和的解析方法EEE MMM d HH:mm:ss yyyy。
我正在使用Spring 4.2.1,Jersey 2.22,它绑定了jackson 2.5.4。
如何获得使用正确格式分析的日期?
更新:进一步考虑,JSON仅用于输出解析。但这可能与JAX-RS参数解析有关。
java ×5
javascript ×2
websphere ×2
angularjs ×1
arrays ×1
aws-lambda ×1
date ×1
ejb ×1
file-io ×1
foreach ×1
jax-rs ×1
jersey ×1
ldap ×1
liferay ×1
node.js ×1
rest ×1
sql ×1
web-services ×1
websphere-7 ×1
websphere-8 ×1
wid ×1