let deal = function (arr) { let stack = [] arr.map(i => { console.info(stack) if (stack.length == 0) { stack.push(i) } else { // duibi tail he i let t = stack[stack.length-1] if (t * i > 0) {// 同方向 stack.push(i) } elseif (t * i <0) {//不同方向 if (t <0 && i >0){ stack.push(i) } elseif (t> 0 && i <0){ //要撞 let value = t + i value = value > 0 ? t:i stack[stack.length-1] = value //维持前面稳定 let change = stack.length > 1 while(change) { t = stack.pop(); tp = stack.pop();
if (tp > 0 && t <0) { value = tp + t value = value > 0 ? tp:t stack.push(value) } else { change = false stack.push(tp) stack.push(t) }}}}} }) return stack }
public <T> T create(final Class<T> service){ Utils.validateServiceInterface(service); if (validateEagerly) { eagerlyValidateMethods(service); } return (T) Proxy.newProxyInstance(service.getClassLoader(), new Class<?>[] { service }, new InvocationHandler() { privatefinal Platform platform = Platform.get(); privatefinal Object[] emptyArgs = new Object[0];
@Overridepublic Object invoke(Object proxy, Method method, @Nullable Object[] args) throws Throwable { // If the method is a method from Object then defer to normal invocation. if (method.getDeclaringClass() == Object.class) { return method.invoke(this, args); } if (platform.isDefaultMethod(method)) { return platform.invokeDefaultMethod(method, service, proxy, args); } return loadServiceMethod(method).invoke(args != null ? args : emptyArgs); } }); }
在craete()中,先对参数final Class service做一个校验,是否是一个interface,是否有继承自其他interface之类的。
Type returnType = method.getGenericReturnType(); if (Utils.hasUnresolvableType(returnType)) { throw methodError(method, "Method return type must not include a type variable or wildcard: %s", returnType); } if (returnType == void.class) { throw methodError(method, "Service methods cannot return void."); }