我有List对象,如果它不为null或为空,我需要获取列表中的第一个元素.
我使用java编写下面的代码,现在我想将其转换为Java 8.
List<DD> container
A<DD,DI> a;
if(container!=null || !container.isEmpty()){
for(DD dd:container)
{
a = dd.getPrescription();
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我这样转换它.
DD detail = container.stream().findFirst().get();
Run Code Online (Sandbox Code Playgroud)
我需要知道这是正确的吗?
我需要转换下面的方法java 8内联函数.需要一些专家的帮助和解释才能做到这一点.
@Override
public boolean a(final Collection<DoseDetailMutableDTO> detailModels) {
for (DoseDetailMutableDTO dd : detailModels) {
final boolean doseDetailTextScheduled = isDoseDetailTextScheduled(dd, 1);
if (doseDetailTextScheduled) {
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
这个intelj IDE有没有捷径?
public static Set<NurseViewPrescriptionWrapper> create(final Set<NurseViewPrescriptionDTO> nurseViewPrescriptionDTOs) {
return nurseViewPrescriptionDTOs.stream()
.map(new Function<NurseViewPrescriptionDTO, NurseViewPrescriptionWrapper>() {
@Override
public NurseViewPrescriptionWrapper apply(NurseViewPrescriptionDTO input) {
return new NurseViewPrescriptionWrapper(input);
}
})
.collect(Collectors.toSet());
}
Run Code Online (Sandbox Code Playgroud)
我将上面的代码转换为 java 8 lamda 函数,如下所示。
public static Set<NurseViewPrescriptionWrapper> create(final Set<NurseViewPrescriptionDTO> nurseViewPrescriptionDTOs) {
return nurseViewPrescriptionDTOs.stream()
.map(input -> new NurseViewPrescriptionWrapper(input))
.collect(Collectors.toSet());
}
Run Code Online (Sandbox Code Playgroud)
现在,我收到声纳问题,例如Lambdas should be replaced with method references“->”这个符号。我该如何解决这个问题?
我看到这样的代码。
if (!substanceList.isEmpty() && (substanceList.size() > 0))
{
substanceText = createAmountText(substanceList);
}
Run Code Online (Sandbox Code Playgroud)
并且,可以这样重构吗?
if (!substanceList.isEmpty())
{
substanceText = createAmountText(substanceList);
}
Run Code Online (Sandbox Code Playgroud)
我想对上面的代码做一些解释,并想知道第二种方式可能会引起一些错误。
int channel[2];
pipe(channel);
Run Code Online (Sandbox Code Playgroud)
我是c编程的初学者,我看到这个代码用于在两个不同的进程之间进行通信.为什么将int [2]数组作为参数传递给我们在管道中使用它?
我们可以将任何大小的数组传递给管道吗?(例如.int channel [5])
我正在使用laravel 5框架进行项目。我想为我的课程传递两个parameter通行DELETE方法Controller。
ex.blade.php
<td align='center'>
{!! Form::open(['method' => 'DELETE', 'route'=>['commitee-page-member.destroy',$member->id ,$commitee->id]]) !!}
<button type="submit" class="btn btn-default btn-sm" onclick="return confirm('Are you sure?')"> <span class="glyphicon glyphicon-trash"></span> </button>
{!! Form::close() !!}
</td>
Run Code Online (Sandbox Code Playgroud)
当我点击按钮,我可以看到variable通过url:
网址:
../masterlaw.com/commitee-page-member/1?5
Run Code Online (Sandbox Code Playgroud)
我尝试不同的方式,采用这two parameters1和5。
控制器类代码:
public function destroy(Request $request, $id)
{
//
echo $id;
echo $request['id'];
}
Run Code Online (Sandbox Code Playgroud)
但是我仍然无法记录retrieve数据。请帮我。
我试着用django 1.6进行项目.但是在代码行5下方传递错误.没有那行,每件事情都可以正常工作.我是新程序员.期待一些专家的帮助.
1 {% extends "base.html" %}
2
3 {% block content %}
4 {% for post in posts_list %}
5 <h2><a href="{% url post slug=post.slug %}">{{ post.title }}</a></h2>
6 <p>{{ post.body|truncatewords:20 }}</p>
7 <p>
8 {{ post.created_at }} |
9 {% with total=post.comments|length %}
10 {{ total }} comment{{ total|pluralize }}
11 {% endwith %}
12 </p>
13 {% endfor %}
14 {% endblock %}
Run Code Online (Sandbox Code Playgroud)
urls.py
from django.conf.urls import patterns, include, url
from django.views.generic import ListView, DetailView
from .models …Run Code Online (Sandbox Code Playgroud) 我需要知道,在java(我的版本jdk 8)中,我可以替换,new DateTime(System.currentTimeMillis())这个代码形式,' DateTime.now()'?
我用过包import org.joda.time.DateTime;
如何在java 8中写同样的东西(日期和时间)?
我写了下面的代码来检查某些情况。
/**
* Returns true if any of the dose detail is an x
* @return boolean
*/
public <DD extends BD<DI>, DI extends BI> boolean Y(final Collection<DD> dds) {
return dds.stream().anyMatch(dd -> dd.M().K());
}
Run Code Online (Sandbox Code Playgroud)
但是此方法有一些风险dds,为空。我需要返回false也是dd也为null。如何使用Java 8将此方法修改为null安全?
我在 NgRx 工作,收到此错误:
“预期有一个赋值或函数调用,但看到的是一个表达式。”
中的声纳问题this.sfForm.get('code')?.[this._mode ? 'disable' : 'enable']();。
我不明白来自声纳的消息,也不明白这里要解决什么问题。我需要一些帮助来理解代码并解决问题。
<mat-form-field [formGroup]="sfForm">
<input Input
matInput
(keydown.enter)="search($event.target.value)"
[type]="''"
formControlName="code"
required>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
sfForm: FormGroup;
private _mode: boolean = true;
public set scanMode(value: boolean) {
this._mode = value;
this.sfForm.get('code')?.[this._mode ? 'disable' : 'enable']();
}
Run Code Online (Sandbox Code Playgroud)