草庐IT

copy_pointer

全部标签

Java8 : how to copy values of selected fields from one object to other using lambda expression

我正在尝试了解java8的新功能:forEach和lambda表达式。尝试重写这个函数:publicTcopyValues(Classtype,Tsource,Tresult)throwsIllegalAccessException{for(Fieldfield:getListOfFields(type)){field.set(result,field.get(source));}returnresult;}使用lambda。我觉得应该是这样的但是做不对:()->{returngetListOfFields(type).forEach((Fieldfield)->{field.set(

java - Files.move 和 Files.copy 抛出 java.nio.file.FileAlreadyExistsException

我想删除一个文件并用旧文件重命名另一个文件,但我无法移动这个文件,因为java抛出java.nio.file.FileAlreadyExistsException以下是代码片段I正在使用staticvoidswapData(StringorigFilePath,StringtempFilePath)throwsIOException{PathtempPath=FileSystems.getDefault().getPath(tempFilePath);PathorigPath=FileSystems.getDefault().getPath(origFilePath);try{Stri

java - Protocol Buffer : get byte array from ByteString without copying

假设我有一个方法voidfoo(byte[]bytes)需要一个字节数组作为它的参数。但是,Protobuf中字节数组的Java类型是ByteString。我可以使用byte[]toByteArray()获取字节数组。但问题是这种方法使用copy来构建一个新的数组,代价比较大。我宁愿它直接返回底层数组,或者返回一个View。是否有任何API,或者性能损失是可以接受的? 最佳答案 通常这是不可能的,因为在ByteString的某些子类中可能没有这样的数组。BoundedByteString可以包含更大的数组,因此需要复制才能获得正确大

java - Possible null pointer dereference of 的说明和修复

代码审查工具提示可能在saveSafeScan(...)中取消引用safeScanWarnings的空指针在行if(safeScanWarnings!=Null&safeScanWarnings.size()>0)我想知道这怎么可能?这是因为我们通过引用返回集合吗?protectedvoidsaveSafeScan(finalResponseresponse,finalDtecdtec)throwsdtecException{CollectionsafeScanWarnings=dtec.getSafeScanWarnings();if(safeScanWarnings!=null&&

Java 抽象类 : Returning "this" pointer for derived classes

我正在尝试使用辅助方法编写一些自定义异常来设置变量,如下所示:publicclassKeyExceptionextendsRuntimeException{protectedStringId;protectedKeyException(Stringmessage){super(message);}protectedKeyException(Stringmessage,Throwablecause){super(message,cause);}publicStringgetId(){returnkeyId;}publicKeyExceptionwithId(finalStringId){

java - COPY FROM 和 Postgres 中的 C3PO 连接池

我的JAVA程序中有以下代码,允许我将数据从文件复制到我的Postgres数据库中:Connectioncon=DriverManager.getConnection("jdbc:postgresql://localhost:####/myDb","myuser","mypassword");CopyManagercm=newCopyManager((BaseConnection)con);cm.copyIn("COPYpricesFROMSTDINWITHDELIMITERAS','",newBufferedReader(newFileReader(filepath)),buffer

Java 垃圾收集器 G1GC 花费很长时间等待 'Object Copy'(疏散暂停)

我不是Java新手,但我对垃圾回收知之甚少。现在我想通过一些实际经验来改变这种状况。我的目标是延迟时间低于0.3秒,或者在极端情况下0.5秒也可以。我有一个带有-Xmx50gb(-Xms50gb)的应用程序并设置了以下其他GC选项:-XX:+UseG1GC-Xloggc:somewhere.gc.log-XX:+PrintGCDateStamps但现在我偶尔会因为垃圾收集而暂停超过5秒,尽管似乎有足够的可用内存。我发现的一个原因:[GCpause(G1EvacuationPause)(young)42G->40G(48G),5.9409662secs]为什么GCG1还在为此做一个“停止

java - `copy(List<? super T> dest, List<? extends T> src) ` 和 `copy(List<T> dest, List<? extends T> src)` 之间的差异

我正在尝试通过阅读以下内容来学习Java泛型通配符:http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeArguments.html#FAQ103Material中有一个例子:publicclassCollections{publicstaticvoidcopy(Listdest,Listsrc){for(inti=0;i我想知道我是否可以按如下方式更改方法签名:publicstaticvoidcopy(Listdest,Listsrc){↓publicstaticvoidcopy(Listdest,Listsrc){这两

Java:使用 nio Files.copy 移动目录

我是nio类的新手,在将文件目录移动到新创建的目录时遇到问题。我首先创建2个目录:FilesourceDir=newFile(sourceDirStr);//thisdirectoryalreadyexistsFiledestDir=newFile(destDirectoryStr);//thisisanewdirectory然后我尝试将现有文件复制到新目录中,使用:PathdestPath=destDir.toPath();for(inti=0;i这会引发以下错误:Exceptioninthread"main"java.nio.file.FileSystemException:des

java - token 端点 : Handling Null Pointer Exception

我尝试通过curl执行此命令从我的oauth2服务器请求代码curl-XPOST-k-vuclientapp:123456http://localhost:8080/oauth/token-H"Accept:application/json"-d"grant_type=authorization_code&scope=read%20write&client_secret=123456&client_id=clientapp&code=appcode&redirect_uri=localhost:3000"响应是*Addinghandle:conn:0x608860*Addinghand