我创建了unique_ptr的两个标准向量:
std::vector<std::unique_ptr<Student>> students;
std::vector<std::unique_ptr<Teacher>> teachers;
Run Code Online (Sandbox Code Playgroud)
然后,我创建一个新对象并将其放在向量中:
students.push_back(std::unique_ptr<Student> (new Student()));
teachers.push_back(std::unique_ptr<Teacher> (new Teacher()));
Run Code Online (Sandbox Code Playgroud)
完成所有操作后,我该如何删除矢量?
Whitout unique_ptr我不得不做一个循环并删除每个对象:
while (!students.empty())
{
delete students.back();
students.pop_back();
}
Run Code Online (Sandbox Code Playgroud)
现在有了unique_ptr我该怎么办?
我知道我必须使用unique_ptr :: reset(我认为).
我正在使用Java中的基本Servlet实现REST Api,但似乎找不到doPatch()方法。
为什么不HttpServlet实现PATCH方法?我想使用它,因为它对于资源更新更有意义。
如果我设置了一个ExecutorService产生ThreadFactory守护线程的 a ,我还需要显式调用该shutdown()方法吗?
Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).build());
Run Code Online (Sandbox Code Playgroud) 我已经阅读了在 Java / ANT 项目中使用 Kotlin 的文档。
我已将构建.xml文件与:
<typedef resource="org/jetbrains/kotlin/ant/antlib.xml">
<classpath>
<pathelement location="lib/kotlin-ant.jar"/>
</classpath>
</typedef>
Run Code Online (Sandbox Code Playgroud)
但我注意到所需的最少库kotlin-ant是:
kotlin-compiler.jar
kotlin-preloader.jar
kotlin-reflect.jar
kotlin-runtime.jar
kotlin-script-runtime.jar
kotlin-stdlib.jar
Run Code Online (Sandbox Code Playgroud)
并且它们必须放置在与 相同的目录中kotlin-ant。
您确认这是使用 ANT 进行编译的正确方法吗?
我需要禁用整个FormGroup特定事件。
然而我注意到FormGroup变成了dirty.
由于我依赖这个dirtyflag,有没有办法避免它?我的意思是,禁用不应导致FormGroup成为dirty.
我在用着FormGroup#disable
我的代码非常简单,这就是为什么我没有发布它。无论如何,我只是将其包裹FormGroup在一个对象中。
public set isDisabled(disabled: boolean) {
if (disabled) {
this.formGroup.disable()
} else {
this.formGroup.enable()
}
}
Run Code Online (Sandbox Code Playgroud) 我目前有一个路线守卫,例如
export class EntityGuard implements CanActivate {
constructor(private readonly router: Router, ...) {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean | UrlTree> {
...
Run Code Online (Sandbox Code Playgroud)
为 URL 激活此防护
basePath/select/10/123
Run Code Online (Sandbox Code Playgroud)
意思是
basePath/select/:type/:id
Run Code Online (Sandbox Code Playgroud)
当满足某个条件时,我需要强制导航回到
basePath/select/:type
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点createUrlTree?例如
if (...) {
return of(this.router.createUrlTree([../', type]));
}
Run Code Online (Sandbox Code Playgroud)
我需要设置
{ relativeTo: parent }
Run Code Online (Sandbox Code Playgroud)
选项。但是我似乎无法找到一种方法来做到这一点。
我目前的解决方案是
private navigateBack(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const end = state.url.indexOf(route.url[route.url.length - 1].path);
const parentUrl = state.url.slice(0, end);
return of(this.router.createUrlTree([parentUrl]));
}
Run Code Online (Sandbox Code Playgroud)
我真的不喜欢。字符串操作对我来说是个大问题。
假设我们有一个object诸如
object MyConstants {
const val ONE: String = "One"
}
Run Code Online (Sandbox Code Playgroud)
生成的字节码类似于
public final class MyConstants {
@NotNull
public static final String ONE = "One";
public static final MyConstants INSTANCE;
private MyConstants() {}
static {
MyConstants var0 = new MyConstants();
INSTANCE = var0;
}
}
Run Code Online (Sandbox Code Playgroud)
INSTANCE有没有办法在保持相同的代码布局的同时避免生成字段?这意味着在 Kotlin 和 Java 中都可以通过类访问字段
MyConstants.ONE
Run Code Online (Sandbox Code Playgroud) 在Java中你可以有:
final Map<String, Supplier<Interface>> associations = new HashMap<>();
associations.put("first", One::new);
associations.put("second", Two::new);
Run Code Online (Sandbox Code Playgroud)
在 Kotlin 中,这翻译为:
val associations: MutableMap<String, Supplier<Interface>> = HashMap()
associations["first"] = Supplier(::One)
associations["second"] = Supplier(::Two)
Run Code Online (Sandbox Code Playgroud)
如果没有kotlin-reflect,这是唯一的方法还是我错过了什么?恕我直言,这看起来不太好或 Kotlinish。
由于有人发生推理错误,这是完整的代码:
fun example() {
val associations: MutableMap<String, Supplier<Interface>> = HashMap()
associations["first"] = Supplier(::One)
associations["second"] = Supplier(::Two)
}
interface Interface
class One : Interface
class Two : Interface
Run Code Online (Sandbox Code Playgroud) 我有一个 RxJS 序列如下:(
控制是一个 Angular FormControl)
control.valueChanges.pipe(
concatMap(cronExprs => from(cronExprs as Array<string>)),
concatMap(cron => this.invokeCronService(cron)),
toArray()
).subscribe(cronExprs => this.setCronExpressionModels(cronExprs))
Run Code Online (Sandbox Code Playgroud)
假设 cronExprs 数组有三个项目['..', '..', '..']。我可以看到,在调试时,concatMap(cron => this.invokeCronService(cron))clojure 被调用了 3 次,但从toArray未被调用过,显然 subscribe clojure 也从未被调用过。似乎序列没有正确完成。
invokeCronService 是:
private readonly invokeCronService =
(cron: string): Observable<CronExpressionModel> =>
this.cronService.describeCron(cron).pipe(
map(result => result.get()),
map((description): CronExpressionModel => ({ cron, description }))
)
Run Code Online (Sandbox Code Playgroud)
describeCron 是一个简单的:
public describeCron(cronExpression: string): Observable<Result<string>> {
return of(Result.valid('', cronExpression))
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
创建项目并指定CSS预处理程序非常简单
ng new my-app --style=scss
... --style=sass
... --style=less
Run Code Online (Sandbox Code Playgroud)
也将默认设置为现有项目
ng config schematics.@schematics/angular:component.styleext scss
... sass
... less
Run Code Online (Sandbox Code Playgroud)
但是,如果我想同时使用Sass和Less怎么办?
这可能吗?
我想这两个结合Ng-zorro,即用Less,以及Clarity,它使用Sass了自定义。
angular ×4
java ×4
kotlin ×3
angular-cli ×1
ant ×1
c++ ×1
c++11 ×1
http-patch ×1
less ×1
rxjs ×1
sass ×1
servlets ×1
std ×1
unique-ptr ×1
vector ×1