为什么在实现接口时允许更改属性中getter或setter的可见性和存在?
interface IFoo
{
string Bar { get; }
}
class RealFoo : IFoo
{
public RealFoo(string bar)
{
this.Bar = bar;
}
public string Bar { get; private set; }
}
class StubFoo : IFoo
{
public string Bar { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
......在实现抽象类时,做同样的事情并不合法吗?
abstract class AbstractFoo : IFoo
{
public abstract string Bar { get; }
}
class RealFoo : AbstractFoo
{
public RealFoo(string bar)
{
this.Bar = bar;
}
// Cannot override because 'Bar' does not …Run Code Online (Sandbox Code Playgroud) 下面的SQL脚本工作与MySQL 17年5月16日及以上,但与一个我的MySQL 5.7.18设施(另一个中,MySQL 5.7.18在泊坞窗容器推出,是OK以及)
drop table if exists bar;
drop table if exists foo;
create table foo (foo_id int not null primary key, description varchar(32));
insert into foo values ("1", "foo-one");
insert into foo values ("2", "foo-two");
create table bar (bar_id int not null primary key, foo_id int null, description varchar(32), foreign key (foo_id) references foo(foo_id));
insert into bar values ("1", "1", "bar-one");
insert into bar values ("2", "1", "bar-two");
alter table bar change column foo_id foo_id int …Run Code Online (Sandbox Code Playgroud)