I have a case where I would like to use a field from a 3rd party package in my package, if that package is not installed in the target org I can use a default value.

[This question](https://salesforce.stackexchange.com/questions/30070/check-managed-app-is-installed-or-not) tells me how I can check if the package is installed, but is it possible to query data from a custom field provided by that package if it exists?

I have tried something like:

```
if(Type.forName('ns__KnownObjectInPackage__c') != null) {
 // SOQL query to return the field value from ns__KnownObjectInPackage__c
}else{
 // Use a default value
}

```

but it will not compile in my dev org complaining that the package is not installed.

Is there any way to do this?