Re: [ceylon-users] Is datasource a valid variable name?

已查看 48 次
跳至第一个未读帖子
已删除帖子

Gavin King

未读,
2016年11月4日 01:41:082016/11/4
收件人 ceylon...@googlegroups.com
The attribute of HikariDataSource you're trying to set is called
"dataSource", not "datasource". See the Javadoc here:

http://www.atetric.com/atetric/javadoc/com.zaxxer/HikariCP/2.4.2/com/zaxxer/hikari/HikariConfig.html#setDataSource-javax.sql.DataSource-

On Fri, Nov 4, 2016 at 5:09 AM, Mohammad Als <karim...@gmail.com> wrote:
> I'm using @bjansen's ceylon-Jooq example and found eclipse as well as
> IntelliJ reporting the following exceptions for the given method:
>
> object datasource extends HikariDataSource(){
> shared void setup(){
> value myds = PGSimpleDataSource();
> myds.databaseName = "sakila";
> myds.user = "postgres";
> myds.password = "postgres";
> myds.url = "jdbc:postgresql://localhost:5432/sakila";
> datasource = myds;
> }
> }
>
>
> Error:ceylon: toplevel value is neither variable nor late and may not be
> specified: 'datasource'
> Error:ceylon: cannot specify value from within its own body: 'datasource'
> Error:ceylon: specified expression must be assignable to declared type of
> 'datasource': 'PGSimpleDataSource' is not assignable to 'datasource'
>
>
> But when I change datasource to dataSource everything works fine. Why is
> ceylon reporting exception if the variable name is datasource (all
> lowercase)?
>
>
> Please help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "ceylon-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ceylon-users...@googlegroups.com.
> To post to this group, send email to ceylon...@googlegroups.com.
> Visit this group at https://groups.google.com/group/ceylon-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ceylon-users/d6cff331-9ff4-42ef-bee5-807e9934c21f%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Gavin King
ga...@ceylon-lang.org
http://profiles.google.com/gavin.king
http://ceylon-lang.org
http://hibernate.org
http://seamframework.org

Mohammad Als

未读,
2016年11月4日 02:17:572016/11/4
收件人 ceylon-users
Well thanks for clarification. 

I've another question though: How is Ceylon differentiating between the object name and the variable name in the given code: 

Name of both the variable name defined in HikariDataSource and that of the object are  dataSource.

object dataSource extends HikariDataSource(){

shared void setup(){
value myds = PGSimpleDataSource();
myds.databaseName = "sakila";
myds.user = "postgres";
myds.password = "postgres";
myds.url = "jdbc:postgresql://localhost:5432/sakila";
        dataSource = myds;
}

Gavin King

未读,
2016年11月4日 03:33:512016/11/4
收件人 ceylon...@googlegroups.com
Well, by the scope. Members of the object hide things declared outside the object.

Sent from my iPhone

Mohammad Als

未读,
2016年11月4日 05:22:232016/11/4
收件人 ceylon-users
Alright thanks... I'm now able to understand the scope concept using the given example:

class A(s){
shared default String s;
}

object s extends A("S"){
shared actual String s = "p";
}

What I'm still failing to understand is why there is no name collision for object s extends A("S") and shared actual String s = "p";

Mohammad Als

未读,
2016年11月4日 05:28:532016/11/4
收件人 ceylon-users
Alryt.. finally got it..:) A variable with the same name as object name can be defined in the object.

class A(){
//shared default String s;
}

object s extends A(){
shared String s = "p";
}

Gavin King

未读,
2016年11月4日 05:47:372016/11/4
收件人 ceylon...@googlegroups.com
The name of the object "s" belongs to an outer scope. The name of the
member "s" belongs to an inner scope. Therefore no collision.
> https://groups.google.com/d/msgid/ceylon-users/4d9e48c0-f686-41b3-87ca-bcefa5ffb9ff%40googlegroups.com.
回复全部
回复作者
转发
0 个新帖子