copy

Is mutating object-parameters in a method(in Java) a bad practice?

随声附和 提交于 2020-03-22 03:44:48
问题 I have a question about mutating method-paramaters(which are objects) in a method. I read and heard multiple times that it is a bad practice to mutate a object in a method which was passed in as a paramater. As example: public void modifyList(List<Object> list) { list.add(new Object()); } Instead, the passed in Object should be copied, the mutation should be performed on the copied object and the copied object should be returned. As example: public List<Object> getModifiedList(List<Object>

Cannot exclude directories for a Gradle copy task

为君一笑 提交于 2020-03-01 04:53:10
问题 I have a gradle script in which I want to copy 3 directories into another folder. But I also have to exclude directories. This is the tree structure I start with: src > java > tms > common src > java > tms > dla src > java > tms > server src > java > tms > javaserver > common src > java > tms > javaserver > dock > transaction > local src > java > tms > javaserver > dock > transaction > tcd src > java > tms > javaserver > dock > transaction > files The folders I want to copy are: src > java >

IOS开发之深拷贝与浅拷贝(mutableCopy与Copy)详解

为君一笑 提交于 2020-03-01 03:59:30
阅读本文之前首先了解copy与retain的区别,如果有不正确的地方望大家多多指教: copy与retain的区别: copy是创建一个新对象,retain是创建一个指针,引用对象计数加 1 。 Copy属性表示两个对象 内容相同,新的对象retain为1 ,与旧有对象的引用计数无关,旧有对象没有变化。copy减少对象对上下文的依赖。 retain属性表示两个对象 地址相同(建立一个指针,指针拷贝),内容当然相同,这个对象的retain值+1 也就是说,retain 是指针拷贝,copy 是内容拷贝。 当然在ios中并不是所有的对象都支持copy,mutableCopy, 遵守NSCopying 协议的类可以发送copy消息, 遵守NSMutableCopying 协议的类才可以发送mutableCopy消息。 假如发送了一个没有遵守上诉两协议而发送 copy或者 mutableCopy,那么就会发生异常。但是默认的ios类并没有遵守这两个协议。 如果想自定义一下copy 那么就必须遵守NSCopying,并且实现 copyWithZone: 方法, 如果想自定义一下mutableCopy 那么就必须遵守NSMutableCopying,并且实现 mutableCopyWithZone: 方法。 首先我们需要有这样的一个前提:   [array addObject:obj];  

Should the Copy trait always be implemented if possible?

前提是你 提交于 2020-03-01 01:50:07
问题 You can implement the Copy trait to give the type copy-semantics instead of move-semantics. This can only be done if all its constituent elements (each factor of a product type, or each factor of each variant of a sum-type) are also Copy . This allows you to also make rather large types Copy . Can implementing Copy be detrimental to performance if the size of the type is "large"? If Copy should always be implemented, why is it not an auto-trait like Sync and Send for those types which can

python list id(L) and id(L[:])

强颜欢笑 提交于 2020-02-24 17:54:44
问题 I'm curious about the difference and relationship between id(L) and id(L[:]) , where L is a list. The official documentation says this about id(): CPython implementation detail: This is the address of the object in memory. But I don't understand why id(L) and id(L[:]) have different values. 回答1: L[:] produces a copy of the list. Its a whole new list contain the same items as L. As a result, its stored in a different place in memory and has a different id. 来源: https://stackoverflow.com

performance of copying directories

会有一股神秘感。 提交于 2020-02-18 05:38:11
问题 I am using C# to copy files from one directory to another directory. I am using code from msdn but its pretty slow taking a minute or so to copy a couple of gigs. It only takes seconds in explorer. http://channel9.msdn.com/Forums/TechOff/257490-How-Copy-directories-in-C Surly there a faster way..:) private static void Copy(string sourceDirectory, string targetDirectory) { DirectoryInfo diSource = new DirectoryInfo(sourceDirectory); DirectoryInfo diTarget = new DirectoryInfo(targetDirectory);

VBA copy rows fast

假装没事ソ 提交于 2020-02-07 01:24:51
问题 I have to work on files with 5000 rows, for each row I have to insert 3 more rows and copy the content in these new rows (after that there will be more steps). My macro works fine but the process of copying the content is really slow, I´m sure there is a solution that works better, any ideas? Sub copy_rows() Application.Calculation = xlCalculationManual Application.ScreenUpdating = False Application.DisplayStatusBar = False Lastrow = Cells(Rows.Count, "A").End(xlUp).Row Lastrow = Lastrow * 4

VBA to find specific text in word doc and copy this text from word doc into a cell in excel

别等时光非礼了梦想. 提交于 2020-02-06 07:57:48
问题 Hello stackoverflow community. What I'm doing until now, is I manually copy a price from the word document, which I previously open, and paste it into an Excel sheet. It is the only .docx file opened at the time on computer, so we just need to find the price in currently opened word file. I'd like U to help me automate this task. This picture shows the part of the document from where I copy the price. In this example it's 605.000. But I don't know the price before I check it in the word file.

VBA to find specific text in word doc and copy this text from word doc into a cell in excel

纵然是瞬间 提交于 2020-02-06 07:56:23
问题 Hello stackoverflow community. What I'm doing until now, is I manually copy a price from the word document, which I previously open, and paste it into an Excel sheet. It is the only .docx file opened at the time on computer, so we just need to find the price in currently opened word file. I'd like U to help me automate this task. This picture shows the part of the document from where I copy the price. In this example it's 605.000. But I don't know the price before I check it in the word file.

How can I duplicate tabPage in c#?

元气小坏坏 提交于 2020-02-03 05:39:09
问题 How can I duplicate a "tabPage" inside of my TabControl? I tried this: //My TabControl: tc //My Tab ID: 0 TabPage newPage = new TabPage(); foreach (Control control in tc.TabPages[0].Controls) { newPage.Controls.Add(control); } tc.TabPages.Add(newPage); but it doesn't work. Thanks in advance. 回答1: I got it! For those who has the same kind of problem, Here is what I’ve done: I had created a UserControl (thanks a lot for @SLaks and @Brian for your tip), copied all objects from my TabControl to