Heavy load for a while, heavy load for a long time.
Recently, I read a book "Groovy in action" to review some of Groovy's syntax features. I am infatuated with the function of this overloaded operator, and I insist on the cool and don't want. Share a Demo.
Because Groovy syntax is slightly different from Java syntax, but it is basically fully compatible with Java syntax, this Demo is still written in Java syntax, which is convenient for everyone to understand.
package com.FunTester.demo import com.fun.frame.SourceCode class demo1 extends SourceCode { public static void main(String[] args) { def s = "fun" * 3 << "fan" println s Demo demo = new Demo() Demo a = new Demo() Demo demo1 = demo + a Demo sssss = demo + 3 Demo fsa = demo * 3 Demo demo2 = demo / 9 Demo demo3 = demo << a Demo demo4 = demo >> a Demo demo5 = demo++ def i = 2 >>> 1 } static class Demo { def plus(Demo demo) { output("Additive object") this } def plus(int s) { output("addition") this } def multiply(int a) { output("multiplication") this } def div(int a) { output("division") this } def leftShift(Demo demo) { output("<<operation") this } def rightShift(Demo demo) { output(">>operation") this } def next() { output("++operation") this } } }
console output
No surprise no surprise!
Next, write one in combination with the thread class of the performance test framework:
RequestThreadTimes requestThreadTimes = new RequestThreadTimes(FanLibrary.getHttpGet(""), 100); List<RequestThreadTimes> threads = requestThreadTimes * 100; new Concurrent(threads).start()
The multiply overload is as follows:
/** * multiplication * * @param i * @return */ public List<RequestThreadTimes> multiply(int i) { ArrayList<RequestThreadTimes> threads = new ArrayList<>(i); i.times { threads << this.clone(); } threads }
Ha, ha, ha!
- There's another big secret: Groovy can override the "." operator.
- Solemnly declare: the article begins with the public number "FunTester", prohibits the third parties (except Tencent cloud) reprint and publish.
Selected technical articles
- java one line code printing heart
- Chinese version of Linux performance monitoring software netdata
- Performance Testing Framework version 2
- How to test the performance of Linux command line interface happily
- Diagram HTTP brain map
- Automatically turn a swagger document into test code
- Five line code to build static blog
- Research on the testing framework of linear interface based on java
- Selenium 4.0 Alpha update log
- Selenium 4.0 Alpha update practice
- How to unify the function, automation and performance test cases of interface test
Selected non-technical articles
- Why choose software testing as a career path?
- Programming thinking for all
- 7 skills to become an automated test
- How to introduce automated testing in DevOps
- Summary of Web automation test failure reasons
- How to introduce automated testing in DevOps
- Common excuses for testers
- Ranking of browser market share in 2019
- API test basis
- API automation test guide
- Future QA Test Engineer