在Java 8中使用默认方法作为穷人的特征是一种安全的做法吗?
一些人声称如果你只是为了它而使用它们可能会让熊猫感到悲伤,因为它很酷,但这不是我的意图.还经常提醒的是,引入了默认方法来支持API演变和向后兼容性,这是事实,但这并不会使它们错误或扭曲以将它们用作特征本身.
我有以下实际用例:
public interface Loggable {
default Logger logger() {
return LoggerFactory.getLogger(this.getClass());
}
}
Run Code Online (Sandbox Code Playgroud)
或许,定义一个PeriodTrait:
public interface PeriodeTrait {
Date getStartDate();
Date getEndDate();
default isValid(Date atDate) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
无可否认,可以使用组合(甚至是辅助类),但它看起来更冗长,更混乱,并且不允许从多态性中受益.
那么,使用默认方法作为基本特征是否可行/安全,还是应该担心不可预见的副作用?
关于SO的几个问题与Java vs Scala特征有关; 这不是重点.我也不仅仅是在征求意见.相反,我正在寻找一个权威的答案或至少是现场洞察力:如果你在公司项目中使用默认方法作为特征,那么它是否真的是一个时间炸弹?
我正在尝试将新的本地分支推product-0.2送到远程,其中已经存在具有相同名称的标记(但分支本身不存在)
git push -v --tags --set-upstream origin product-0.2:product-0.2
Pushing to https://****@github.com/mycompany/product.git
error: src refspec product-0.2 matches more than one.
error: failed to push some refs to 'https://****@github.com/mycompany/product.git'
Run Code Online (Sandbox Code Playgroud)
与:相同:
git push origin product-0.2:/refs/heads/product-0.2
Run Code Online (Sandbox Code Playgroud)
虽然相反的方式有效,例如创建一个分支product-0.1,然后提交它然后应用标记product-0.1.
有些人通过在本地删除冲突标记,然后推送分支,然后检索远程标记来解决这个问题,但它看起来很麻烦且容易出错.
如何以最小的麻烦创建我的分支?
感谢您的输入
这次我试图模拟一个服务(做http调用)来测试一个组件.
@Component({
selector: 'ub-funding-plan',
templateUrl: './funding-plan.component.html',
styleUrls: ['./funding-plan.component.css'],
providers: [FundingPlanService]
})
export class FundingPlanComponent implements OnInit {
constructor(private fundingPlanService: FundingPlanService) {
}
ngOnInit() {
this.reloadFundingPlans();
}
reloadFundingPlans() {
this.fundingPlanService.getFundingPlans().subscribe((fundingPlans: FundingPlan[]) => {
this.fundingPlans = fundingPlans;
}, (error) => {
console.log(error);
});
}
}
Run Code Online (Sandbox Code Playgroud)
该文件(2.0.0版本)解释说,你应该嘲笑的服务.使用相同的TestBed配置:
describe('Component: FundingPlan', () => {
class FundingPlanServiceMock {
getFundingPlans(): Observable<FundingPlan> { return Observable.of(testFundingPlans) }
}
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [FundingPlanComponent],
providers: [
{ provide: FundingPlanService, useClass: FundingPlanServiceMock },
]
});
fixture …Run Code Online (Sandbox Code Playgroud) 我有一个名为的图像目录images,其中包含图像文件:
images
--0001.png
--0002.jpg
--0003.png
Run Code Online (Sandbox Code Playgroud)
现在我想将此目录上传到我的 azure blob 存储,并具有相同的文件结构。我查看了此处和此处给出的示例代码,但是:
azure-blob-storage,该软件包中也没有这样的东西BlobService。我们有一个庞大的Java 8 Spring Hibernate Maven项目.
问题 :
我们现在的工作方式
Parent
|--- Tier1
|--- Tier2
|--- WebTier
|---- ModuleA
|---- ModuleB
|---- ModuleC
|---- ...
|---- Entities
|---- Shared
|---- Batch
|---- IntegrationTests
WebTier)作为人工制品从Eclipse或IntelliJ 部署到其本地TomcatShared在需要"跨模块"访问的模块放置其服务的地方让它变得更好的想法
MessageBroker模块以允许相关的松耦合.也许是JMS,或者只是一个用于同步通信的哑内存组件Shared模块Entities.至少核心业务实体(Customer,CustomerFile,...).但是一些实体显然属于单个模块(批处理执行信息将在Batch模块中)这样,任何进行更改的人在ModuleA大多数情况下只会在该模块中构建和运行测试,而不必担心破坏应用程序.
问题
一些指标
谢谢你!
在Grails 3.1.12中,我想对服务进行单元测试:
@Transactional
class PlanService {
List<Plan> getPlans(Map params) {
def currentUser = (User)springSecurityService.getCurrentUser()
return Plan.findAllByCompany(currentUser.employer, params)
}
}
Run Code Online (Sandbox Code Playgroud)
像这样:
@TestFor(PlanService)
@Mock([Plan, User, Company])
class PlanServiceSpec extends Specification {
void "Retrieve plan from the current user"() {
setup:
// create and save entities here
when: "the plans are retrieved"
def params = null
def plans = service.getPlans(params)
then: "the result should only include plans associated to the current user's company"
plans.size() == 2
}
Run Code Online (Sandbox Code Playgroud)
从控制台运行测试:
grails> test-app my.PlanServiceSpec -unit
Run Code Online (Sandbox Code Playgroud)
失败: …
至少运行 VICE 2.4:
PRINT PEEK(53280)
254
POKE 53280,14
PRINT PEEK(53280)
254
Run Code Online (Sandbox Code Playgroud)
很明显,只使用了位#0-#3,并且使用 获得了“正确”值AND 15,但是为什么6510 将高位设置为1?